Custom ThreadPool in Java to Perform as ThreadPool in C# based on Singleton Model
2013-03-21 10:24
519 查看
Every process has a default ThreadPool with defalut size 25 in .Net application development. It is very convenient as writing ThreadPool.QueueUserWorkItem(CallBack);
As so far, I have not found a default tool class to do the same thing in JDK1.6.
So, I try to complete one based on Singleton Model.
As so far, I have not found a default tool class to do the same thing in JDK1.6.
So, I try to complete one based on Singleton Model.
public class CustomThreadPool{ private BlockingQueue<Runnable> workQueue; private ThreadPoolExecutor poolExecutor; pirvate static CustomThreadPool customThreadPool; private CustomThreadPool(){ if(workQueue == null){ workQueue = new LinkedBlockingDeque<Runnbale>(); } if(poolExecutor == null){ poolExecutor = new ThreadPoolExecutor(5, 25, 1, TimeUnit.DAYS, workQueue); } } public static void queueUserWorkItem(Runnble workItem){ if(customThreadPool == null){ customThreadPool = new CustomThreadPoll(); } customThreadPool.poolExecutor.execute(workItem); } }
相关文章推荐
- Hashtable and HashMap are two hash based collection in Java and used to store objects as key value p
- Exception in thread "main" org.javalite.activejdbc.InitException: failed to determine Model class na
- Units Problem: How to read text size as custom attr from xml and set it to TextView in java code
- Units Problem: How to read text size as custom attr from xml and set it to TextView in java code
- A better way to shutdown the thread pool in Java
- Units Problem: How to read text size as custom attr from xml and set it to TextView in java code
- How to create different types of thread pool in Java
- Introduction to Thread Pools in Java
- how to list tabes based on column name in sybase?
- A new way to perform parameter validation in C# 3.0
- how to implement C# ref in Java
- java.lang.IllegalStateException: closed when trying to access response in onResponse(Response respon
- How to sort a Map<Key, Value> on the values in Java?
- Use loop-based procedure to perform a bubble sort on a list of data
- MS bug "The connection pool" in Oracle 10g and the data sort according to specified filed on DataGrid control.
- The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path:
- How to terminate a thread in Java
- Exception in thread "pool-1-thread-15" java.lang.OutOfMemoryError: Java heap space
- java.lang.RuntimeException: Handler{405c1180} sending message to a Handler on a dead thread
- Exception in thread "main" java.lang.InternalError: Can't connect to X11 window