• 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

Multithreading a request in the server

 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ???
 
author and jackaroo
Posts: 12200
280
Mac IntelliJ IDE Firefox Browser Oracle C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Aaah thx very much, I intend to use RMI, so that will not be a problem then.
Thx again
 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
reply
    Bookmark Topic Watch Topic
  • New Topic