• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

threads question!

 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
// 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.)
 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"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
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 223
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
xi brian
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i got the idea
thank you very much for your help
reply
    Bookmark Topic Watch Topic
  • New Topic