ServerSocketChannel pour accepter plus de connexions du même client

mon serveur doit accepter les nouvelles connexions du même client. Parce que mon client se reconnecte après 10 heures de connexion. C’est un serveur / client pour le protocole iscsi et mon client est un initiateur Microsoft iscsi.

Je voudrais donc une suggestion. Aujourd’hui, j’ai un pool de threads de taille 4, mon serveur peut donc accepter 4 connexions à partir du même client. Mais ce nombre pourrait augmenter à mesure que mon temps de connexion est important. Le code est ci-dessous …. Dois-je terminer le threadPool et renvoyer la connexion? C’est la meilleure approche?

Merci d’avance.

ExecutorService threadPool = Executors.newFixedThreadPool(4); // Create a blocking server socket and check for connections try { // Create a blocking server socket channel on the specified/default port System.out.println("0"); serverSocketChannel = ServerSocketChannel.open(); // Making sure the socket is bound to the address used in the config. serverSocketChannel.socket().bind( new InetSocketAddress(getConfig().getTargetAddress(), getConfig().getPort())); System.out.println("0.1"); serverSocketChannel.configureBlocking(true); System.out.println("0.2"); System.out.println("1"); while (running) { System.out.println("2"); // Accept the connection request. // If serverSocketChannel is blocking, this method blocks. // The returned channel is in blocking mode. final SocketChannel socketChannel = serverSocketChannel.accept(); System.out.println("3"); // deactivate Nagle algorithm socketChannel.socket().setTcpNoDelay(true); connection = new TargetConnection(socketChannel, true); System.out.println("4 - "); try { final ProtocolDataUnit pdu = connection.receivePdu(); // confirm OpCode if (pdu.getBasicHeaderSegment().getOpCode() != OperationCode.LOGIN_REQUEST) throw new InternetSCSIException(); // get initiatorSessionID LoginRequestParser parser = (LoginRequestParser) pdu.getBasicHeaderSegment().getParser(); ISID initiatorSessionID = parser.getInitiatorSessionID(); /* * TODO get (new or existing) session based on TSIH But since we don't do session reinstatement and * MaxConnections=1, we can just create a new one. */ TargetSession session = new TargetSession(this, connection, initiatorSessionID, parser.getCommandSequenceNumber(), parser.getExpectedStatusSequenceNumber()); // set ExpCmdSN (PDU is immediate, hence no ++) sessions.add(session); System.out.println("5 - sessions.size(): " + sessions.size()); threadPool.submit(connection);// ignore returned Future // connection.call(); } catch (DigestException | InternetSCSIException | SettingsException e) { System.out.println("TargetServer: " + new ToSsortingngBuilder(sessions).reflectionToSsortingng(sessions).toSsortingng()); LOGGER.info("Throws Exception", e); continue; } }