Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

InterruptedException in lock() method

 
Alexey Ivanov
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,

I'm probably raising the old problem, the matter is the infamous InterruptedException.

I've carefully read this thread, apparently it makes sense for me.
However, here is where I'm kinda stuck. I have the following lock method signature:


So I'm going to implement the method something like this:


I'm pondering what to do in the catch block after re-interruption. I guess I can't leave it as is since a thread will break through my wait/notify defence after re-interruption. So the 2 options I'm considering are:
1) kick a thread back to waiting state immediately after re-interruption (I feel it contradicts the common sense of interruption)
2) throw a runtime exception after re-interruption (and here I'm afraid I can violate the requirement that a thread should always wait until a locked record becomes available).

Could you give me an argument in favor of one of these alternatives to help me make a final decision? (or there can be the 3rd way?)

Thanks in advance.
 
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
A possible solution is explained here. Take a look at "Noncancelable tasks"
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic