Forums Register Login

NX: RMI and threads

+Pie Number of slices to send: Send
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 :-)
+Pie Number of slices to send: Send
 

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.
+Pie Number of slices to send: Send
Keep things Simple
I agree, you're working too hard.
M
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
 

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.
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 884 times.
Similar Threads
B&S: OK to assume lock(), update(), unlock() called from same thread?
NX: Locking and Unlocking and Sun's Must Conditions
Passed SCJD
Defence using current thread as client's ID
NX: RMI and thread safe
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 03:53:22.