我在 Java 中有一个 SSLServerSocket,当客户端连接时,我为其通信创建一个线程:
System.setProperty("javax.net.ssl.keyStore", "keystore");
System.setProperty("javax.net.ssl.keyStorePassword", "password");
SSLServerSocket server = (SSLServerSocket)null;
if(ipSocket == null){
ipSocket = new HashMap<String,java.net.Socket>();
}
try {
SSLServerSocketFactory sslserversocketfactory = (SSLServerSocketFactory) SSLServerSocketFactory.getDefault();
server = (SSLServerSocket) sslserversocketfactory.createServerSocket(4380);
log.info("Server started");
} catch(IOException e) {
e.printStackTrace();
}
while(true){
try {
SSLSocket client = (SSLSocket) server.accept();
log.info("new client");
} catch (Exception e){
e.printStackTrace();
}
}
问题是代码有时会拒绝连接。它发生在代码运行一段时间时,所以我认为问题是客户端失去了连接并重新连接,但之前的线程仍然存在,并且有一个最大值 SSLServerSockets。
这会发生吗?最大数是多少?
发生断开连接时如何杀死线程?