| Author |
threads question!
|
xi brian
Greenhorn
Joined: Mar 06, 2008
Posts: 29
|
|
// Locks a record so that it can only be updated or deleted by this client. // Returned value is a cookie that must be used when the record is unlocked, // updated, or deleted. If the specified record is already locked by a // different // client, the current thread gives up the CPU and consumes no CPU cycles // until the record is unlocked. public long lockRecord(long recNo) throws RecordNotFoundException; // Releases the lock on a record. Cookie must be the cookie // returned when the record was locked; otherwise throws SecurityException. public void unlock(long recNo, long cookie) throws SecurityException; questions. 1.Returned value is a cookie that must be used when the record is unlocked (does this cookie must be the recNo ?) 2.If the specified record is already locked by a different client, the current thread gives up the CPU and consumes no CPU cycles until the record is unlocked. (does the above mean that when current client tries to update a record which is updating by another client. the current client does not allow to do so or the current client has to wait until the lock is released.)
|
 |
Vinicius Florentino
Greenhorn
Joined: Feb 26, 2008
Posts: 16
|
|
1- No. It's better other, like a random, a sequencial... 2- To update the current client need to LOCK first, if other client is updating, the current will wait the lock release to get the rec lock and do something
|
 |
xi brian
Greenhorn
Joined: Mar 06, 2008
Posts: 29
|
|
"No. It's better other, like a random, a sequencial..." please give me a little bit more information on this part. i am really stuck here
|
 |
Simon Hogg
Greenhorn
Joined: Jan 29, 2008
Posts: 7
|
|
The returned value from lock() should be the cookie that you use for unlock(). For example to update a record you need to do something like this (pseudocode): What Vinicius is saying is that in the lock method you need to create and return a unique (long) value that you use anywhere the cookie is requested. The cookie can either be from a sequence (e.g. the first call to lock() returns 1, the second returns 2, the third 3, etc.) or a random number and not be related to the record number at all.
|
 |
Anne Crace
Ranch Hand
Joined: Aug 29, 2005
Posts: 223
|
|
This is how I handled the cookie. This method is called from inside the lockRecord(long recNo) method. I declare a variable, long lockCookie = createLockCookie(recNo); Hope this helps. There are lots of ways to deal with the cookie.
|
SCJP, SCJD
|
 |
xi brian
Greenhorn
Joined: Mar 06, 2008
Posts: 29
|
|
i got the idea thank you very much for your help
|
 |
 |
|
|
subject: threads question!
|
|
|