我的 Java.NIO 套接字服务器中有一个线程池。我有时会收到运行时错误,例如Connection reset by peer
orBroken Pipe
等。
我的问题是:抛出异常时线程是否被杀死?如果是 - 是否在线程池中创建了一个新线程来代替被杀死的线程?
这是我的线程管理器:
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));
}
}