SCJP 1.4<br />SCJD<br />SCWCD 1.4
2) I've read other posts on this forum, in other people's opinion, 'locking' is used when you want to book/update a record, but right after booking, the record is unlocked, as Frans Janssen said:
client A: read record 1, seems to be not booked
client B: read record 1, seems to be not booked
client A: lock, update and unlock record 1: record 1 is now booked for A
client B: lock, update and unlock record 1: record 1 is now booked for B
so if B books the record right after A books it, what is the point of locking?
SCJP 1.4, SCJD
Originally posted by Samuel Pessorrusso:
You can not use any class of nio package. Read your assingment again.
The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
Originally posted by Andrew Monkhouse:
You must conform to the instructions you have been provided by Sun, however you may find that your instructions do not specify anything at all regarding NIO. You might like to look at this post for more information.
Regards, Andrew
SCJP 1.4<br />SCJD<br />SCWCD 1.4
SCJP 1.4<br />SCJD<br />SCWCD 1.4
I think most people are only doing logical locking - the scenario suggested by Frans can be handled without resorting to physical locking.Originally posted by Shu Gao:
Does locking requries logic locking or physical locking, I was thinking about physical locking few days ago that I decided to use java.nio.channels FileLock that locks a portion of a file to accomplish this, what's everyone else's choice?
In other words, if you rely on this class for your locking, you run the risk of having you locking fail on the assessor's computer if they are running on a different operating system (very very minor risk).From the FileLock API:
Whether or not a lock actually prevents another program from accessing the content of the locked region is system-dependent and therefore unspecified.
Consider the following code that might be written by some junior / bad programmer:If you did not check the cookie then this code would work even if some other client owned the lock. You should defensively program your Data class so that such a scenario will not only fail but will throw the SecurityException.Originally posted by Shu Gao:
can you still tell me under which circumstances that unlock() will throw that SecurityException?
wait() will work fine - most people use thisOriginally posted by Shu Gao:
My question is that "give up the CPU and consumes no CPU cycles", does it mean the thread gives up totally? I was thinking about wait() at first
The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
Originally posted by Andrew Monkhouse:
Hi Shu, If you did not check the cookie then this code would work even if some other client owned the lock. You should defensively program your Data class so that such a scenario will not only fail but will throw the SecurityException.
wait() will work fine - most people use this
Regards, Andrew
[ August 02, 2005: Message edited by: Andrew Monkhouse ]
SCJP 1.4<br />SCJD<br />SCWCD 1.4