• Post Reply Bookmark Topic Watch Topic
  • New Topic

RMI Server Object Instances  RSS feed

 
David Garratt
Ranch Hand
Posts: 216
Eclipse IDE Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hopefully a simple question with a simple answer. Do server side objects created work like servlets with a single instance of a RMI object being used by multiple clients, or is a separate object created for each client instance created. I suspect the latter, but if there was a way to accomplish something like the former it would be better for me.

Thanks

Dave
 
Edward Harned
Ranch Hand
Posts: 291
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Each client request uses a separate thread on the RMI Server. Any objects created by the threads will be garbage collected at some time.

You can share Class variables between threads as long as you protect access.

You can use Singleton Classes etc. Just about anything you can do with a non-RMI environment you can do with an RMI Server. The trick is to keep the garbage collector at bay.

What I use is in the start up Class (that contains the main()) is to save the _impl instance and any other instances I need across multiple threads as Class variables and issue a never ending wait(). That is, I never exit the main() method so the instance variables always have a live reference.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!