I have developed a RMI application in which server accepts clients username and password, then creates a socket with it and communicate via socket.
My server code is
Problem arising when the server remains idle, doing no work, it automatically closed.
I do not know why it happening, but think it might be the Garbage Collector killing my server as it is not doing any work and occupying a port.
On windows the server runs fine either any work is there or no work is there, but it only happens on linux that the server stops.
I have a question regarding following code.
Is server goes under waiting mode until new request of connection comes from the client? or what happens here because this code is in while loop executing n times.
Thanks in advance
You need to make sure the server itself cannot be GCed (such as making the reference a Class object).
Not a problem in this case.
Reachable objects are determined from Threads, it a Thread is executing the accept() method the objects defined inside the main method have references on the stack and are reachable.
Aneesh Vijendran wrote:This code is fine for a single thread. Did you imagine what would happen when a few user's (Least two) connect to this server concurrently? Would it be able to serve? I would suggest you to make it multi threaded.
Yes I have made the program multithread.
I have tried to run my server with nohup command and it works