• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Multithreading a request in the server

 
Frank Verbruggen
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Allthough I know it isnt explicitly required:

should I use a seperate thread for each request from a client or not ?

Thoughts please ???
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 12014
220
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Frank,

Are you using RMI or Sockets?

If you are using RMI, then the RMI server will be creating new threads for each connected client (which means you must ensure your server code is thread safe).

If you are using Sockets, then you should create a new thread for each client, otherwise you will be limited to one connected client at any given time.

Under the "Locking" section of your instructions, you probably have a statement similar to "Your server must be capable of handling multiple concurrent requests...". To meet this requirement you will need to have multi threaded code.

Regards, Andrew
 
Frank Verbruggen
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Aaah thx very much, I intend to use RMI, so that will not be a problem then.
Thx again
 
Zafer Abu saeed
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Andrew:

If you are using RMI, then the RMI server will be creating new threads for each connected client (which means you must ensure your server code is thread safe).


But as far as I know, a request to a remote server could cause a
new Thread to be created (and could reuse an already created Thread).

see this from the RMI 1.4 specs:


A method dispatched by the RMI runtime to a remote object implementation
may or may not execute in a separate thread. The RMI runtime makes no
guarantees with respect to mapping remote object invocations to threads.

 
Frank Verbruggen
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have heard that before,
but for my application it does not matter what the actual object is that is running the thread.
My code isn't concerned with identifying clients, so doesnt need information from the thread.
There is another topic somewhere in this forum, stating that u can reinforce the making of different threads for each request if u might need such a thing.
Good luck and thx again
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic