我有一个在JBoss中运行的应用程序.我有一个传入的Web服务请求将更新ArrayList
.我想每隔60秒从另一个班级轮询这个列表.这样做最有效的方法是什么?
有谁能指出我一个很好的例子?
Ada*_*ski 16
我还建议使用ScheduledExecutorService,它提供了更高的灵活性Timer
,TimerTask
包括使用多个线程配置服务的能力.这意味着如果特定任务需要很长时间才能运行,则不会阻止其他任务开始.
// Create a service with 3 threads.
ScheduledExecutorService execService = Executors.newScheduledThreadPool(3);
// Schedule a task to run every 5 seconds with no initial delay.
execService.scheduleAtFixedRate(new Runnable() {
public void run() {
System.err.println("Hello, World");
}
}, 0L, 5L, TimeUnit.SECONDS);
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
5057 次 |
最近记录: |