This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Little Book of Impediments (e-book only) and have Tom Perry on-line!
See this thread for details.
Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

RMI Thread Spawning.

 
Anton Golovin
Ranch Hand
Posts: 527
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, guys. I am working on my Developer's Certification, aided in this task by Habibi's great book. I finally got to the point where I understand the need for adapter class and the actual remote class, and find the whole setup very elegant and simple.

But I've got a question from the area of RMI. I, from reading about RMI, understood that once a request comes in via the RMI server, the server automatically spawns a thread for each client. The programmer need not concern himself with explicitly writing thread code to handle multiple clients. The RMI creates threads automatically.

I was just going to ask for your input: if my understanding was indeed on the mark, or if I missed something.

And as always, I don't mean to ask elementary questions, but, unfortunately, I can't figure it out to certainty myself.

Thanks for your valuable time!
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 12012
216
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Anton,

Yes, RMI will automatically create new threads (or reuse existing threads) to handle incomming calls. So you do not have to write any special code to make your server handle multiple simultaneous clients.

This means that you must write all your server code to be thread safe.

One thing you need to be aware of though, is that there is no guarantees that the thread a particular client uses for one method call will be the same thread it uses for a later method call. It is possible that client 'A' will use one thread to call lock() and a different thread to call unlock(). Or client A could use one thread to call lock() and client B could use the same thread to call lock(). (This may not bother you if you are using thin clients or if you are using lock cookies).

Regards, Andrew
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic