[英]Java - thread Pool
我的预定线程池--->
private static ScheduledExecutorService pendingCheckScheduler = Executors.newScheduledThreadPool(1);
线程1 --->
private ScheduledFuture<?> pendingTranStatusCheckHandle=pendingCheckScheduler.scheduleAtFixedRate(new PendingTranStatusCheck(),0,checkForPendingTrans,TimeUnit.SECONDS );
线程2 --->
private ScheduledFuture<?> forcibleBatchCloseHandle=pendingCheckScheduler.schedule(new ForcibleBatchClose(), waitForPendingTrans, TimeUnit.MINUTES);
Thread 1
每10秒执行一次。 Thread 2
应该在30分钟后启动。
Thread 1
的行为符合预期,而预期在30分钟后开始的Thread2
在1小时后开始。
是否在等待thread1
正在促进这个问题?如果是这样, thread2
应该当线程1点结束考虑到我们在线程pool.Why只有一个线程被givcen优先级Thread2
被拉伸过长后1小时开始?
我一无所知,希望有一些指点。请帮助我。
这是因为您在执行程序中只有一个线程。
Executors.newScheduledThreadPool(1);
它导致第二次Runnable等待,直到第一个Runnable完成。
尝试使用两个线程:
Executors.newScheduledThreadPool(2);
您的概念有些偏离,这抵消了您的结论。 您总共有一个线程 ,并且计划在该线程上运行两个任务 。 因此,如果重复执行的任务长时间执行并占用线程,则绝对可以预期会有干扰。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.