我的调度线程池->
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 Thread2在1小时后被拉伸得太长而无法启动?
我一无所知,希望得到一些pointers.Please的帮助。
发布于 2013-04-25 16:58:55
你的概念略有偏差,这抵消了你的结论。您总共有一个线程,并且计划在该线程上运行两个任务。因此,如果重复的任务长时间执行,占用线程,您肯定会受到干扰。
发布于 2013-04-25 16:58:22
这是因为你在executor中只有一个线程。
Executors.newScheduledThreadPool(1);它会导致第二个可运行的等待,直到第一个可运行的完成。
尝试使用两个线程:
Executors.newScheduledThreadPool(2);https://stackoverflow.com/questions/16210420
复制相似问题