• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Lock()

 
Matt Pavlovich
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey guys,

I'm trying to wind things up, and so I ran the thread test here in the forum. Thanks to Roberto for that, by the way. I have ran it many, many times, and it is always under 1 second. I even ran it with 1000 threads and it did not hang. However, I did not ever see "waiting..." on my screen should the following code be hit in my lock():



Since these records are placed in the locked records map for fractions of a second, and the methods delete and update are thread safe, should I ever really see that the thread has blocked? I even tried to run two of the thread test classes at the same time, and even then it did not show up. Do you guys think I could be doing this wrong? It seems odd to me. Is there anyway to test that my wait and notify()'s are working correctly?

Thanks for your input.
Matt
 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The 1st question you should ask yourself: when should this waiting-message be shown? If you can answer that one, I'm quiet sure you'll be able to setup a little test program which displays the waiting-message to the console. I could give you the answer, but then I would spoil all your fun, so give it a shot
 
Matt Pavlovich
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Roel,

Ironically, a sleep() should do it if I am not mistaken. That's what I get for writing this question at 4am. However, I now see that I am only generating a lockCookie value one time, which is an even bigger issue. So when my server connects, it gets generated once and everyone that connects to the server uses the same lockCookie. Not sure what I did but that's not right. If I am not mistaken, each thread in the thread test should generate it's own lockCookie value, yes? That's how I understand the instructions, anyway.

Back to the drawing board...

Thanks.
Matt
 
Matt Pavlovich
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Roel,

Okay, I pinpointed it. I used static initializer methods for I everything, and so my RecordVault class only ever has one lockCookie value. So I fixed all that, and now even if I try to delete just one record, the thread goes into waiting, even though there is no way the current record could be in the lockedRecords map since it is the only record that is trying to be deleted.

If really don't get how

could ever be hit if I haven't even called the put method yet!!?

Thought I was so close to being done...maybe not. Any ideas what I may have done? I cannot see it...

As always, thanks.
Matt
 
Matt Pavlovich
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay...all sorted. What a nightmare...
 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To delete a record you should also have the lock. And after actually deleting the record you should always unlock the record again.
 
Matt Pavlovich
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes all good in that department. That is how my logic for both the update and delete (and book) methods works. I just had a few kinks to work out, and now wait and notify hit as they should.

 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Matt Pavlovich wrote:and now wait and notify hit as they should.

Glad to hear you sorted it out
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic