SCJP (1.4 | 5.0), OCJP (6.0), OCMJD
Sean Keane wrote:
so it's not clear to me how his lock method could know if a client already holds a lock on a particular record...
Ryan Small wrote:
Sean Keane wrote:
so it's not clear to me how his lock method could know if a client already holds a lock on a particular record...
A common scheme I've seen is to use the thread's ID.
SCJP (1.4 | 5.0), OCJP (6.0), OCMJD
Sean Keane wrote:But this does work in the context of using RMI?
Sean Keane wrote:
Maybe someone with more knowledge of RMI can comment, but my understanding was that you could not guarantee clients requests would always run in the same thread. Therefore you can't rely on Thread.currentThread.getId() to identify a client when using RMI.
SCJP, SCWCD, SCJD
SCJP (1.4 | 5.0), OCJP (6.0), OCMJD
Roel De Nijs wrote:You could of course code a work-around and implement a similar system to the one people without a lockCookie in the interface implemented to identify the clients, but that would make the lockCookie quiet useless.
SCJP (1.4 | 5.0), OCJP (6.0), OCMJD
SCJP (1.4 | 5.0), OCJP (6.0), OCMJD
Sean Keane wrote:But I don't see how this stops the client with id of 999 calling the lock method a second time?
Roel De Nijs wrote:
Sean Keane wrote:But I don't see how this stops the client with id of 999 calling the lock method a second time?
It doesn't stop the client from calling lock method a second time, but nothing will. But my code will prevent a client from locking a record twice or locking multiple records at the same time (if the API is used correctly)
SCJP (1.4 | 5.0), OCJP (6.0), OCMJD
Sean Keane wrote:If I simply take your Data class (not your Business Service class) and I call the lock-method twice, what prevents me from locking it twice?
Roel De Nijs wrote:So if you decide in a multi-threaded environment to just invoke the lock-method a few times, you won't be able to do that (and your stuck in the same situation as the lockCookie-interfaces).
Roel De Nijs wrote:If you use the API correctly (identifying the client/thread before a given set of methods), you'll get an IllegalStateException when you try to lock more than 1 record at a time
SCJP (1.4 | 5.0), OCJP (6.0), OCMJD
Sean Keane wrote:Is my understanding correct here?
Sean Keane wrote:So, one thing I'm curious about this, why didn't you throw an IllegalStateException I the unlock-method is called without the client id being set in advance?
Roel De Nijs wrote:
Sean Keane wrote:So, one thing I'm curious about this, why didn't you throw an IllegalStateException I the unlock-method is called without the client id being set in advance?
Don't understand what you exactly mean, there is something weird about that sentence.
SCJP (1.4 | 5.0), OCJP (6.0), OCMJD
Sean Keane wrote:Why didn't you throw an IllegalStateException when the lock-method is called without the client id being set in advance?
Roel De Nijs wrote:
Sean Keane wrote:Why didn't you throw an IllegalStateException when the lock-method is called without the client id being set in advance?
Ah, now I understand and that's an easy one: you only have to set the client id when you work in a multi-threaded environment.
SCJP (1.4 | 5.0), OCJP (6.0), OCMJD
Roel De Nijs wrote:My previous explanation was not 100% complete. This is the full version: you only have to set the client id when you work in a multi-threaded environment where you don't have the guarantee that consecutive calls by a client are not handled by the same thread (like with RMI).
SCJP (1.4 | 5.0), OCJP (6.0), OCMJD
Sean Keane wrote:How is that different to your original explanation?
Roel De Nijs wrote:If you have a multi-threaded environment where each request of a client is handled by the same thread you don't have to set the client-id.
SCJP (1.4 | 5.0), OCJP (6.0), OCMJD
Sean Keane wrote:Are you doing a check inside the lock-method to see if the client-id is set, and if it is not set then you are assuming that you can identify a client by the ID of the thread?
SCJP 5, SCWCD 5, SCBCD 5
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
|