We help IT Professionals succeed at work.

RMI and concurrency issue

nhuanvn
nhuanvn asked
on
Hello Experts,

I am dealing with RMI, writing some code using it.
They work fine for clients sequentially, but I wonder
if I can make this code run concurrently to serve
clients. As I realize, 1 remote object can serve
the requests sequentially, but I don't see how to
deal with concurrency.

Could you please direct me how to deal with concurrency
when using RMI ?

Much more points and grade A will be my very thanks to
you.
Comment
Watch Question

Commented:
Hi,

the problem has an easy solution - if the clients share the same resources all the time (complicated math calculations, updates or else) and then disconnect - you can do nothing!
You can use synchronized methods - so one clients query have to wait until the previous query is done.

Example:

public String getMsg() throws RemoteException {
    return msg;
}

This method does not need to be synchronized and all the clients can access it concurrently.
But if you update/change or set sone data - your method HAVE to be synchronized:

public synchronized void setMsg(String newMsg) throws RemoteException {
    msg = newMsg;
}

You have to be extremly carefull if you use updates to Collections. They use to be synchronized... but are not, so Exceptions may arrise.

Author

Commented:
I've made a test to see if the clients run concurrently,
and they do. So it is the right answer that we don't HAVE
TO do anything, not that we CAN DO NOTHING.
Thank you for your tip on the Collections.
Cheer !
:-)

Author

Commented:
I've made a test to see if the clients run concurrently,
and they do. So it is the right answer that we don't HAVE
TO do anything, not that we CAN DO NOTHING.
Thank you for your tip on the Collections.
Cheer !
:-)

Author

Commented:
I've made a test to see if the clients run concurrently,
and they do. So it is the right answer that we don't HAVE
TO do anything, not that we CAN DO NOTHING.
Thank you for your tip on the Collections.
Cheer !
:-)

Author

Commented:
I've made a test to see if the clients run concurrently,
and they do. So it is the right answer that we don't HAVE
TO do anything, not that we CAN DO NOTHING.
Thank you for your tip on the Collections.
Cheer !
:-)

Author

Commented:
I've made a test to see if the clients run concurrently,
and they do. So it is the right answer that we don't HAVE
TO do anything, not that we CAN DO NOTHING.
Thank you for your tip on the Collections.
Cheer !
:-)

Author

Commented:
I've made a test to see if the clients run concurrently,
and they do. So it is the right answer that we don't HAVE
TO do anything, not that we CAN DO NOTHING.
Thank you for your tip on the Collections.
Cheer !
:-)

Author

Commented:
I've made a test to see if the clients run concurrently,
and they do. So it is the right answer that we don't HAVE
TO do anything, not that we CAN DO NOTHING.
Thank you for your tip on the Collections.
Cheer !
:-)

Commented:
I'm glad to help you :)

Commented:
Mmmm... do you accept the answer?

Author

Commented:
Of course I do, but there's a problem with
the Java stub from Experts-exchange that I can't submit
mine. This is another trial.

Explore More ContentExplore courses, solutions, and other research materials related to this topic.