• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Issue with multiple threaded delete access in lock manager

 
Mark O' Sullivan
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I'm currently having an issue with running multiple-threaded access for the delete method of assignment. The method works say 3 out of 4 times and then can enter deadlock. I will post code in hope someone spots a problem. I have 2 caches a valid and deleted record numbers cache. Below is my lock method.

This is probably fairly standard.
in delete method, just check is the record number passed locked by passed cookie

Anyone spot anything in my logic, that could be wrong? Any suggestions are very welcome, as one can imagine, multi-threaded issues are difficult to resolve!
Thanks.

 
Roel De Nijs
Sheriff
Posts: 9815
101
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mark,

First a code remark:

Why don't make it a checkRecNo method which will throw RNFE when recNo is invalid. A lot less lines of code and code would become a lot easier to read (in my opinion).


I'm completely not familiar with the new locking api (used wait/notifyAll/synchronized), but it seems the isRecordNumberValid is a static method because RoomReservationFileAccess seems a class (if it is an object name, it should not start with capital letter). Are you sure these static methods are thread-safe too?
I guess with your logic is nothing wrong, because in my application I used similar logic:
a) check recNo
b) wait (if record is already locked)
c) check recNo
d) lock record by adding recNo to a map

Kind regards,
Roel
 
Mark O' Sullivan
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Solved this issue. I was calling notify() instead of notifyAll() on the condition variable when unlocking. Damn, that was difficult to detect. Have take Roel's comments on board, and was already throwing the RNFE exception from the isRecordNumberValid function, just I'm new to Exception handling so I was creating unneccessary code in the lock function. Alls well again for Halloween time! Can go trick or treating!
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 11854
185
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Mark

Why not have the RoomReservationFileAccess.isRecordNumberValid method throw the Exception if the record doesn't exist?

Note: there can be valid reasons for not doing this, just curious as to what your reasons are.


Doh - didn't see Roel's comment and your response. Should have known better than to post my own comments before reading his.
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 11854
185
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also - why not catch the InterruptedException in the outer try...finally block?

And - you are currently just swallowing the InterruptedException. I hope you plan to at least log it.
 
Mark O' Sullivan
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
God, the great Andrew Monkhouse responded to one of my questions! Great day, appreciate the input and the SCJD book is great as well! Thanks!
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 11854
185
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Heh - you can blame my lack of responses on Roel and Roberto. When I see that they are taking an active interest in a topic I usually feel that there is little left for me to add.

Glad you like the book.
 
Roberto Perillo
Bartender
Posts: 2271
3
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Andrew Monkhouse wrote:When I see that they are taking an active interest in a topic I usually feel that there is little left for me to add.


Honestly, I feel really honored to read this. Andrew, thanks for the words. It feels really good to know that we are able to help people, and it's also fun! We'll continue to help people, and I'm sure my good buddy Roel also thinks like me!
 
Roel De Nijs
Sheriff
Posts: 9815
101
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Roberto Perillo wrote:and I'm sure my good buddy Roel also thinks like me!

Of course, you know what they say about great minds
 
Bernd Wollny
Ranch Hand
Posts: 59
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

the first call of RoomReservationFileAccess.checkRecNo(recNo); is it really necessary?
If the record is deleted no one has the ability to change it (or to lock it), if it doesn't exist there's no reason to wait for lock... So, why to do the first check?

Regards
Bernd
 
Roel De Nijs
Sheriff
Posts: 9815
101
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bernd Wollny wrote:the first call of RoomReservationFileAccess.checkRecNo(recNo); is it really necessary?

No, it isn't.

Kind regards,
Roel
 
Bernd Wollny
Ranch Hand
Posts: 59
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Roel De Nijs wrote:
Bernd Wollny wrote:the first call of RoomReservationFileAccess.checkRecNo(recNo); is it really necessary?

No, it isn't.

That's what i wanted to hear, thanks!

Regards,
Bernd
 
Bernd Wollny
Ranch Hand
Posts: 59
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,

perhaps you have already noticed that i have the same locking strategy within my locking manager...
So, one follow-up question:
Due to safety reasons i have to make my check-record-no method thread-safe too....but, i was wondering if a read lock is enough or if i have to use a
write lock when checking it (it == my map storing record information)? What are your thoughts?

@Roel:
How did you handle the InteruptedException finally? I saw some post from you where you wrote that you are using

instead of wrapping it up into some user-defined RuntimeException, right? Was that your final decision or did you change before submitting to SUN?

Kind regards
Bernd
 
Roel De Nijs
Sheriff
Posts: 9815
101
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Bernd,

According to your 1st question: In my assignment I didn't use read and write locks, just synchronized the complete methods, so I'm not an expert in this matter. I would think a read lock is just fine, because check-record-no method would in my opinion just need to read to your map (and not write).

This thread is not about InterruptedException and how to handle it, so I'm not going to answer this question here because we should try to stick as much as possible to "1 thread for 1 question"-policy. So it becomes for other people trying to look for answers a lot easier to find what they are looking for. So feel free to post your question in a new thread or in the thread I started.

Kind regards,
Roel
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic