【发布时间】:2013-04-19 02:12:30
【问题描述】:
我的预定线程池--->
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 的行为符合预期,而 Thread2 预计在 30 分钟后开始,而在 1 小时后开始。
thread1 中的延迟是否会导致此问题?如果是这样,考虑到线程池中只有一个线程,thread2 应该在线程 1 完成时具有优先级。为什么Thread2 被拉伸太长1 小时后开始?
我一无所知,期待一些指点。请帮助我。
【问题讨论】:
-
您应该将代码块用于真实代码。排除“Thread 1-->”让他们成为评论的东西。换行符也有助于提高可读性。
-
好的。我会在下一篇文章中按照您的指示进行操作。不知怎的,我忘记了。
标签: java scheduled-tasks threadpool threadpoolexecutor