• Post Reply Bookmark Topic Watch Topic
  • New Topic

server stops running

 
rajshkhr pandey
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello to all,

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
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Note that the accept() method can throw an IOException which will exit the loop and thus your program.

Bill
 
Edward Harned
Ranch Hand
Posts: 291
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
GC is always a concern.

You need to make sure the server itself cannot be GCed (such as making the reference a Class object).

You also need to make sure the remote object reference is not GCed (s/a (this is the return of UnicastRemoteObject.exportObject() or whatever you use).
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Bill
 
Aneesh Vijendran
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Cheers
Aneesh
 
rajshkhr pandey
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Cheers
Aneesh


Yes I have made the program multithread.
I have tried to run my server with nohup command and it works
Problem solved
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!