SCJP 1.4<br />SCJD 1.4
Originally posted by Daniel Simpson:
I am planning on using a map for key-value pairs representing the record # and lock cookie, respectively. My question is when I call lock, what type of number should be returned? A random number? One that is incremented? For those who have had success in their locking techniques, what did you do? Thanks!
--------<br />Andy Zhu<br />scjp 1.4<br />scjd 1.4<br />SAS Certified Programmer 9.0
SCJP 1.4<br />SCJD 1.4
Anton Golovin ([email protected]) SCJP, SCJD, SCBCD, SCWCD, OCEJWSD, SCEA/OCMJEA [JEE certs from Sun/Oracle]
public long nextLong() - Returns the next pseudorandom, uniformly distributed long value from this random number generator's sequence. The general contract of nextLong is that one long value is pseudorandomly generated and returned. All 2^64 possible long values are produced with (approximately) equal probability.
As I understand, the use of cookie is to identify the record, rather than the thread/client, if your locking mechanism is correct. Therefore, use of a record id as a cookie is perfect; I don't see how a random number can play here.
B.S. University of Wisconsin<br />SCJP 1.4 (85%)<br />SCJD 1.4 (92%) B&S Contractors
Originally posted by Anton Golovin:
Hi, Andy. It's a great and elegant idea, but it defeats the purpose of having a cookie in the first place - every thread can request a record number, and if it became known that the record number is the cookie, there could be security issues...
Originally posted by Anton Golovin:
Hi, Andy. It's a great and elegant idea, but it defeats the purpose of having a cookie in the first place - every thread can request a record number, and if it became known that the record number is the cookie, there could be security issues...
Originally posted by Matt Sheehan.:
I would argue that using the record number is the simplest way to generate a unique cookie for each record and that security issues involving the cookie are probably beyond the scope of the assignment.
SCJP 1.4<br />SCJD 1.4
Anton Golovin ([email protected]) SCJP, SCJD, SCBCD, SCWCD, OCEJWSD, SCEA/OCMJEA [JEE certs from Sun/Oracle]
// 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;
--------<br />Andy Zhu<br />scjp 1.4<br />scjd 1.4<br />SAS Certified Programmer 9.0
Originally posted by Andy Zhu:
First, Mat: don't do this. your compromised implementation is wrong:
record a: 1, rand = 33, cookie: 34
record b: 11, rand = 23, cookie: 34
You know what's going on.
--------<br />Andy Zhu<br />scjp 1.4<br />scjd 1.4<br />SAS Certified Programmer 9.0
Originally posted by Andy Zhu:
Hey, Mat: sorry I didn't read your code carefully. But, in my assignment, recNo is a long. How about yours?
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
|