Hi all, I was trying out the same set of RMI server codes on MAC OSX and Windows XP platform, both using Java 6.
Strangely, in MAC OSX, the server keeps running (in terminal), whereas in Windows, the server starts and stops (in command prompt).
After some googling, it seems that in some cases, the remote object was GCed very soon, and hence the server stops.
Moving the 'service' declaration out of main method (as a static reference) fixed this problem. However, I'm not sure if this is the correct way of solving this problem. Anyone has any comment on this approach?
posted 10 years ago
Just found out if my remote object extends UnicastRemoteObject, this would not be a problem. Not too sure why
Like Jari also mentioned it's not necessary to do both: extend from UnicastRemoteObject and use exportObject. I decided to use the exportObject-method (and make it possible in future to let my service implementation class extend from some generic service class).
Ad Tan wrote:Moving the 'service' declaration out of main method (as a static reference) fixed this problem. However, I'm not sure if this is the correct way of solving this problem. Anyone has any comment on this approach?
I did that too, but too solve another issue I experienced. Take a look here for more details.
When you call UnicastRemoteObject.exportObject(), you should pass 0 as argument. Maybe that's the problem.
Cheers, Roberto Perillo
SCJP, SCWCD, SCJD, SCBCD
posted 10 years ago
Jari Timonen wrote:Extend UnicastRemoteObject or use exportObject. Not both
Oooh, sorry wasn't too clear in my posting, in my findings, the 2 methods can be used to launch the server. However, the exportObject method would not allow the server to continue running (the Thread will finish running) unless I put the remote instance in a static variable.
I tried Roberto's suggestion... but no success either.
He's my best friend. Not yours. Mine. You can have this tiny ad:
Devious Experiments for a Truly Passive Greenhouse!