Thursday, August 03, 2006

Thread pool, J2SE 5's new feature

I just implemented a route searching engine who's able to figure out the shortest path in a maze. As there are thousands of threads running in the program, a thread pool might be a good choice. Thread pool is a new feature of J2SE 5. In my opinion, it's a much better feature than CachedRowSet, which is also a new feature in J2SE5 advertised by SUN.
A thread pool can be acquired by using the following statement:
ExecutorServer threadPool = Executors.newFixedThreadPool(1000);
Then, use threadPool to execute threads:
threadPool.execute(seekerThread1);
I compared 2 implementations using JRE 1.4 and JRE 1.5. The one using thread pool is much more efficient than the one without using thread pool. Maybe it's especially useful for application with a lot of threading work.

No comments: