package jp.itohiro.raspitools.stats.receiver;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.net.Socket;

public class StatsReceiver {
    private static final Logger LOGGER = LoggerFactory.getLogger(StatsReceiver.class);
    private static final ReceiverProperties RECEIVER_PROPERTIES = new ReceiverProperties();

    public static void main(String[] args) {
        try {
            ServerSocket server = new ServerSocket();
            server.setReuseAddress(true);
            server.bind(new InetSocketAddress(RECEIVER_PROPERTIES.getReceiverPort()));
            LOGGER.info("Ready to receive request...");
            while(true){
                Socket socket = server.accept();
                LOGGER.info("Connection established.");
                new Thread(new InputHandler(socket, RECEIVER_PROPERTIES)).start();
            }

        } catch (IOException e) {
            LOGGER.error("Failsed to listen to port: " + RECEIVER_PROPERTIES.getReceiverPort(), e);
        }
    }
}

@@ -214,16 +214,148 @@
 .Socket;
+%0Aimport java.util.concurrent.ExecutorService;%0Aimport java.util.concurrent.Executors;%0Aimport java.util.concurrent.ThreadPoolExecutor;
 %0A%0Apublic
@@ -555,16 +555,109 @@
 rties();
+%0A    private static final ExecutorService EXECUTOR_SERVICE = Executors.newFixedThreadPool(4);
 %0A%0A    pu
@@ -1098,18 +1098,32 @@
     
-new Thread
+EXECUTOR_SERVICE.execute
 (new
@@ -1169,16 +1169,8 @@
 ES))
-.start()
 ;%0A  

use thread pool executor instead of direct thread invocation