Skip to Main Content

Java APIs

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Concurrency

843793Apr 23 2004 — edited May 19 2004
ok i have a Java RMI system that works, but is Java RMI concurrent?
In Socket Programming the server is set to listen for connections and
when a connection has been made it spawns a new thread to allow a new
connection to exist in a seperate thread but as far as the client is
concerned the thread is the server.

Can this be done in RMI or is RMI itself concrruent?


Thanks for the help


Rabi.

Comments

843793
RMI is concurrent Rabi,

it will make the threads automatically. If parts of your called implementation are not threadsafe, you should synchronize the critical regions. In general it is poor form to synchronize the remote method itself. (It can too easily lead to long backlogs at best, and deadlocks at worst)

John
843793
ok thanks Cajo, I suspected it was from looking at the Bind code statement as you have to type new i just wanted confirmation. In terms of critical regions such as a common buffer store of data and a published file of data these would be best served as a seperate class, is that one way of doing it?
843793
Yes, a separate class is certainly a valid technique to accomplish this.

More simply might be to have remoted methods call synchronizied non-remote methods of the same class, to perform the non-thread safe operations.

[url https://cajo.dev.java.net/index.html]John
843793
Yes, a separate class is certainly a valid technique
to accomplish this.

More simply might be to have remoted methods call
synchronizied non-remote methods of the same
class, to perform the non-thread safe operations.

[url https://cajo.dev.java.net/index.html]John
Hi,

well cajo can you explain to me in a example what u mean by
- have remoted methods call synchronizied non-remote methods of the same class, to perform the non-thread safe operations.

Thanks.
Clement
843793
No problem Clement,

Let's suppose you have this implementation for a remotely accessible object:
public class Foo ... {
   public void bar(...); { // this is a remotely callable method

      // do some non-critical, i.e. threadsafe stuff ...

      if (condition) // perhaps based on a condition, or not
         baz(...);   // this is a cricial section

      // maybe do some final non-critical stuff ...

   }
   protected synchronized void baz(...) { // this is not remotely callable
      // it doesn't really need to be protected, but looks better that way
      // do the critical, i.e. non-threadsafe operations here ...
   }
}
Hope this makes sense.
843793
Hi John,

Hmm, I just want to confirm with you if my understanding is correct.
I am doing some kind of booking system.
I am doing the implementation in RMI.

First i have a client to login and this properbly will be handled by the ConnectionManager and then it will keep track of all clients (regardless of whether it is a user / adminstrator).
Then if the client wants to book a ticket, all the bookings will be handled by the BookingManager.

That means the client will be in the non-critical section unless the BookingManager assigns a key to the client to access the critical section. So in this case there will be only one client doing the booking, am i right?

But what i dun understand is how threads can be used in this case.
Can you enlighten me?
Thanks.

Clement
843793
Hello Clement,

When you expose an object for remote access, the underlying RMI framework will each calling client its own thread automatically. If you synchronize the exposed method(s), only one client will be allowed in at a time, this can create large backlogs, and even connection rejects, in a busy system.

In most objects, very little of its code is really not threadsafe. A booking in your case, would not be threadsafe, i.e. you don't want two clients to get the identical booking, whereas the booking manager, generally would be threadsafe. Generally speaking, the more agressively you minimize your critical regions, the better the overall system performance, under high loading.

John
1 - 7
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Jun 16 2004
Added on Apr 23 2004
7 comments
165 views