Schedule multiple tasks in one thread

I want a single thread to maintain responsibility for completing multiple tasks at different intervals. I want to add and remove tasks from the scheduler. Are there any libraries that can help me with this. If not, I will code my own, I just don't want to reinvent the wheel.

For the background, I want to add an alert to my application, controlled from one thread, where the rest of the application can add / remove scheduled tasks. I can use multiple TimerTask or write my own single-threaded scheduler, but if there is a better option, I do not want to ignore it.

James

+3
source share
3 answers

-, JDK 1.5 , ScheduledExecutorService?

http://download.oracle.com/javase/6/docs/api/java/util/concurrent/ScheduledExecutorService.html

, , factory:

http://download.oracle.com/javase/6/docs/api/java/util/concurrent/Executors.html#newSingleThreadScheduledExecutor()

factory, ThreadFactory . Thread, ScheduledExecutorService. , Thread.setName, . . , , , , JVM.

Thread.setDaemon(true), JVM.

, ExecutorService , , ExecutorService.shutdown ExecutorService.shutdownNow. (, finally) . , , , , , - ExecutorService. JavaDocs.

+4
+1

Quartz. Java. , .

0

All Articles