• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

server stops running

 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Note that the accept() method can throw an IOException which will exit the loop and thus your program.

Bill
 
Ranch Hand
Posts: 291
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Do the next thing next. That’s a pretty good rule. Read the tiny ad, that’s a pretty good rule, too.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic