请问关于用threadPoolExecutor实现threadpool的问题?# Java - 爪哇娇娃
w*e
1 楼
我原来的一个简单的tcpserver是每次有连接就创建一个新的thread,就像这样
Socket connectionSocket = serverSocket.accept();
new myThread(connectionSocket, CoreDB).start();
现在想改成threadpool,本来想自己写,但是发现有一个非常简单的
ThreadPoolExecutor,用起来就象这样
Socket connectionSocket = serverSocket.accept();
threadPoolExecutor.execute(new myThread(connectionSocket));
help里面说ThreadPoolExecutor有最小count和max count,thread数量低于min count的
时候每次都创建新的thread,在min count和max count之间只有queue满的时候才会创建
新的thread,如果已经达到max count而且queue也满了就会转给rejecthandler.
我不太理解的是概念上的问题,我的
Socket connectionSocket = serverSocket.accept();
new myThread(connectionSocket, CoreDB).start();
现在想改成threadpool,本来想自己写,但是发现有一个非常简单的
ThreadPoolExecutor,用起来就象这样
Socket connectionSocket = serverSocket.accept();
threadPoolExecutor.execute(new myThread(connectionSocket));
help里面说ThreadPoolExecutor有最小count和max count,thread数量低于min count的
时候每次都创建新的thread,在min count和max count之间只有queue满的时候才会创建
新的thread,如果已经达到max count而且queue也满了就会转给rejecthandler.
我不太理解的是概念上的问题,我的