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 :-)