public class LockManager{
private static HashMap hashmap;
private static LockManager instance = null;
public static synchronized getInstance(){
if(instance==null) instance=new LockManager();
return instance;
}
public synchronized lock(int rec,Object o){...}
...
}
... so All the clients will have only single LockManager ,right?
Should I put the hashmap in a static state?
Should I use 'public void synchronized lock(int,Object){}' or 'synchronized(hashmap){}'?
So if one thread comes along and place the value �1� in the HashMap all other threads must wait until that thread is finished even if they want to lock the record �5�,for the lock is synchronized.
How should I do that?
Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
No. Check the map with locks.containsValue(record) and if the record is not in the map, map that client to the record with locks.put(client, record); otherwise call wait(). Do the inverse in unlock.
scwcd, scjd, scjp<br /><a href="http://natejohnson.us" target="_blank" rel="nofollow">http://natejohnson.us</a><br /><a href="http://rice.kuali.org" target="_blank" rel="nofollow">http://rice.kuali.org</a>
I mean When Client A is booking and has lock(5),
then client B wants to book at the same time and
B's record number is 6.
For the sake of the same object to LockManager and the synchronized method 'lock()',B will not allow to process the method lock until A has been out of the block synchronized.
I know I have wrong in some place,but I don't know where it is.
Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
scwcd, scjd, scjp<br /><a href="http://natejohnson.us" target="_blank" rel="nofollow">http://natejohnson.us</a><br /><a href="http://rice.kuali.org" target="_blank" rel="nofollow">http://rice.kuali.org</a>
scwcd, scjd, scjp<br /><a href="http://natejohnson.us" target="_blank" rel="nofollow">http://natejohnson.us</a><br /><a href="http://rice.kuali.org" target="_blank" rel="nofollow">http://rice.kuali.org</a>
Originally posted by Ray Cheeny:
I have a method doBooking() which deal with lock,read,modify,write,unlock.
But I don't know where it should be, in server(like RemoteAccess or FactoryConnection) or in client?
How about you?
scwcd, scjd, scjp<br /><a href="http://natejohnson.us" target="_blank" rel="nofollow">http://natejohnson.us</a><br /><a href="http://rice.kuali.org" target="_blank" rel="nofollow">http://rice.kuali.org</a>
But I don't know where it should be, in server(like RemoteAccess or FactoryConnection) or in client?
Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
if two clients attempt to perform the sequence lock, read, modify, write, unlock concurrently, then both modification attempts will be handled correctly.
Originally posted by Ray Cheeny:
Does that mean when one client is modify the record
,the other client could not just read the record?
I think it should be read,lock,...
scwcd, scjd, scjp<br /><a href="http://natejohnson.us" target="_blank" rel="nofollow">http://natejohnson.us</a><br /><a href="http://rice.kuali.org" target="_blank" rel="nofollow">http://rice.kuali.org</a>
Consider Paul's rocket mass heater. |