aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes NX: RMI and threads Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "NX: RMI and threads" Watch "NX: RMI and threads" New topic
Author

NX: RMI and threads

Fari Lho
Greenhorn

Joined: Mar 02, 2004
Posts: 2
The implementation of the Java Developer assignment was my first experience with RMI and I would really like some comments on a couple of things (also concerning the use of threads).
My lock method in the database suspends the thread calling it if the record is locked and invokes it again when the record is unlocked (are using wait and notify). In my RMI implementation of the lock method which the clients call I do something like this:
public void lock(int param1, int param2) throws RemoteException
{
LockingThread lockingThread = new LockingThread();
lockingThread.setParameter1(param1);
lockingThread.setParameter2(param2);
lockingThread.setParameter3(someMethod(param1));
Thread t = new Thread(lockingThread);
t.start();
}
The LockingThread class implements Runnable. In the LockingThread�s run method the database/record lock method is called. The LockingThread performs a callback to the client when the lock is acquired.
The first thing I would really like comments on are:
1)Assuming my database is thread safe, is there any way this code is not? Does the RMI implementation take care of this (by using different threads) so that the parameters may under no circumstances get mixed up if several clients call the same method simultaneously?
When I look at the code now the use of a class, LockingThread, that implements Runnable instead of extending Thread looks like a bad choice. The idea behind it was that I would make some kind of reusable thread pool in my RMI implementation to run the �LockingThread� objects in to limit the number of threads needed.
Comments wanted on:
2)Does the concept of using Runnable objects and a reusable thread pool look good?
3)Have I just managed to make a small overhead by using Runnable instead of Thread for my �LockingThread�, when I dropped the use of a thread pool? Should I have change this, and do you think it will not matter for the grading of my assignment?
Will appreciate any comments :-)
Satish Avadhanam
Ranch Hand

Joined: Aug 12, 2003
Posts: 697
Originally posted by Fari Lho:
The implementation of the Java Developer assignment was my first experience with RMI and I would really like some comments on a couple of things (also concerning the use of threads).
My lock method in the database suspends the thread calling it if the record is locked and invokes it again when the record is unlocked (are using wait and notify). In my RMI implementation of the lock method which the clients call I do something like this:

It seems that you are using two lock methods, one for local and for remote implementations. Is that right?


The LockingThread class implements Runnable. In the LockingThread�s run method the database/record lock method is called. The LockingThread performs a callback to the client when the lock is acquired.
The first thing I would really like comments on are:
1)Assuming my database is thread safe, is there any way this code is not? Does the RMI implementation take care of this (by using different threads) so that the parameters may under no circumstances get mixed up if several clients call the same method simultaneously?
When I look at the code now the use of a class, LockingThread, that implements Runnable instead of extending Thread looks like a bad choice. The idea behind it was that I would make some kind of reusable thread pool in my RMI implementation to run the �LockingThread� objects in to limit the number of threads needed.
Comments wanted on:
2)Does the concept of using Runnable objects and a reusable thread pool look good?
3)Have I just managed to make a small overhead by using Runnable instead of Thread for my �LockingThread�, when I dropped the use of a thread pool? Should I have change this, and do you think it will not matter for the grading of my assignment?
Will appreciate any comments :-)

Hi Fari, I don't think this will help but anyway I want to say. As far as I remember, I never read of anyone using Thread pool for the scope of the assignment. It may be a bit complex or I don't know why. For the sake of assignment, many people follow and advice the famous "Keep things Simple" rule. So its just only an advice and by the way, am still doing the assignment. Maybe anyone who has completed project will comment on this.
Max Habibi
town drunk
( and author)
Sheriff

Joined: Jun 27, 2002
Posts: 4118
Keep things Simple
I agree, you're working too hard.
M


Java Regular Expressions
Fari Lho
Greenhorn

Joined: Mar 02, 2004
Posts: 2
Satish Avadhanam
I do not have two locking mechanisms (I use two locks though, one for controlling which client may update the record and one to prevent read/write operations from messing with each other). I could have used the same locking mechanism for local and remote client, but for the local client I really do not care to much about locking since this is only one client accessing a local instance of the database. I keep some things simple :-)
I must admit I started out thinking about too complex solutions but I did narrow the scope after a while and ended up with what I hope is a simple and correct working application.
Satish Avadhanam
Ranch Hand

Joined: Aug 12, 2003
Posts: 697
Originally posted by Fari Lho:
Satish Avadhanam
I do not have two locking mechanisms (I use two locks though, one for controlling which client may update the record and one to prevent read/write operations from messing with each other). I could have used the same locking mechanism for local and remote client, but for the local client I really do not care to much about locking since this is only one client accessing a local instance of the database. I keep some things simple :-)
I must admit I started out thinking about too complex solutions but I did narrow the scope after a while and ended up with what I hope is a simple and correct working application.

Hi Fari, first you can call me Satish
About the two locks, I really do not understand. I only used one lock and that's record locking. This is used only for a couple of functions -- delete, update(this is also used as business specific book method). For all other operations I did not use any locking mechanism. I want to document about the potential issues arising b'se of this, primarily dirty reads.
And one more question Fari -- Did you use two different classes i.e. one for remote clients with full locking mechanism and one for local clients with NO locking mechanism?
Also am curious to know how two locks are implemented? If you can throw some light on it...that would be great.
Thanks.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: NX: RMI and threads