ScheduledExecutorService中的方法
时间: 2023-08-27 12:11:09 浏览: 94
ScheduledExecutorService是Java中用于调度任务的接口,它继承了ExecutorService接口,因此可以执行异步任务。它提供了以下方法:
1. schedule(Runnable command, long delay, TimeUnit unit):在指定延迟时间后执行一次指定任务。
2. schedule(Callable<V> callable, long delay, TimeUnit unit):在指定延迟时间后执行一次指定任务,并返回任务的执行结果。
3. scheduleAtFixedRate(Runnable command, long initialDelay, long period, TimeUnit unit):以固定的频率重复执行指定任务。
4. scheduleWithFixedDelay(Runnable command, long initialDelay, long delay, TimeUnit unit):每次执行任务时,会在上一次执行完成后的delay时间后再次执行。
5. submit(Callable<V> task):提交一个Callable任务,并返回一个Future对象,表示任务的执行结果。
6. submit(Runnable task):提交一个Runnable任务,并返回一个Future对象,表示任务的执行结果。
7. shutdown():关闭执行器,不再接受新的任务提交。
8. shutdownNow():尝试立即停止所有正在执行的任务,并返回尚未执行的任务列表。
除此之外,ScheduledExecutorService还提供了一些用于调整线程池大小、获取执行器状态等的方法。
阅读全文
相关推荐
![-](https://img-home.csdnimg.cn/images/20241231044901.png)
![-](https://img-home.csdnimg.cn/images/20241231045021.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)