File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Distributed Java and the fly likes server stops running Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Distributed Java
Reply Bookmark "server stops running " Watch "server stops running " New topic
Author

server stops running

rajshkhr pandey
Ranch Hand

Joined: Oct 14, 2009
Posts: 35
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

Joined: Mar 22, 2000
Posts: 12326
    
    1
Note that the accept() method can throw an IOException which will exit the loop and thus your program.

Bill


Java Resources at www.wbrogden.com
Edward Harned
Ranch Hand

Joined: Sep 19, 2005
Posts: 290

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).


Ed's latest article: A Java Parallel Calamity http://coopsoft.com/ar/Calamity2Article.html
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12326
    
    1
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

Joined: Jun 29, 2008
Posts: 125
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


Cheers
Aneesh
rajshkhr pandey
Ranch Hand

Joined: Oct 14, 2009
Posts: 35
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
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: server stops running
 
Similar Threads
simple socket programming
Doubt in Sockets!!
Connection Refused Error
Socket chat problem
java.net Socket port number question