我在我的Java.NIO套接字服务器中使用了线程池。有时我会收到运行时错误,比如“Connection reset by peer”或“Broken Pipe”等。
我的问题是:当抛出异常时,线程是否被杀死?如果是的话,线程池中会创建一个新的线程来代替被杀死的线程吗?
这是我的ThreadManager:
我的问题是:当抛出异常时,线程是否被杀死?如果是的话,线程池中会创建一个新的线程来代替被杀死的线程吗?
这是我的ThreadManager:
import java.nio.channels.SocketChannel;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public class ThreadsManager {
private ExecutorService threadPool = null;
private LiveConnectionsManager liveConnectionsManager;
private int threadPoolSize = 35; //number of tasks thread
public ThreadsManager(LiveConnectionsManager liveConnectionsManager) {
this.liveConnectionsManager = liveConnectionsManager;
threadPool = Executors.newFixedThreadPool(threadPoolSize);
ServerActions.threadPool = threadPool;
}
public void processNewMessage(SocketChannel socketChannel, Client client)
{
threadPool.execute(new MessagesProcessor(socketChannel, client, liveConnectionsManager));
}
public void closeConnection(SocketChannel socketChannel, Client client) {
threadPool.execute(new LogoutClient(socketChannel, client, null));
}
}