Q:

how can calculate the cost for running up to 500 working threads

I implemented a system to handle 500 socket connections using Java, each connection in its own thread.
So when all connection are alive, I have 500 Threads running.
Will a server Intel® Xeon® Processor E5620 with 8 GB of RAM be enough to handle all these threads?
Whether the answer is yes or no, how can I calculate the cost?
sample code:
    Executor executor = Executors.newFixedThreadPool(500);
    ServerSocket serverSocket = null;
    Socket socket;

    try {
        serverSocket = new ServerSocket(port);

    } catch (IOException e) {
        e.printStackTrace();
    }

    while (true) {
        try {

            if (serverSocket != null) {
                socket = serverSocket.accept();
            } else {
                continue;
            }

            SocketClient client = new SocketClient(socket);//socket client is responsible for handling string values that will be read from socket, and insert values to the DB

            executor.execute(client);

        } catch (IOException e) {
            connectedDevices.remove("Unknown" + i);
        }
    }

Thanks.

A:

Any more-or-less modern computer will handle 500 threads, it is not a problem (I suppose you do not allocate GBs of memory in each of them)
problem - how long it will take for each thread to finish it's execution when all 500 are run simultaneously
for example if each thread do not block others via shared resources (like db), and takes 1 second from start to finish, and we have 8 thread cpu - this will mean that only 8 thread will run really simultaneously, so each second only 8 threads will finish, other will wait to start, so last thread will finish approximately in 63 seconds, common timeout is about 30-60 seconds, this will mean that results of last thread will not reach the client
so, to do approximate understanding you can calculate execution time of one thread (T seconds or miliseconds), and then you will find how many requests per second your server will be able to handle
of course it will be very aproximate value, as context switching between threads also takes time

