Saturday, July 23, 2011

Managing Thread Pools

I have copied and run a sample program as from here



here the ExecutorService

particularly valuable are the isTerminated() and awaitTermination(long timeout, TimeUnit unit) methods.

Fantastic also the possibilily to submit a task and monitor its execution with a Future object.

There is also an API to schedule a task in the future, without having to use a java.util.Timer or a framework like Quartz:

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


Anyway using a ThreadPoolExecutor is far superior to allocating and managing directly Threads yourself (never again a new Thread(this) !)

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

No comments: