Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
  • Piet Souris
  • salvin francis
  • fred rosenberger

InterruptedException in lock() method

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.
Posts: 11604
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A possible solution is explained here. Take a look at "Noncancelable tasks"
Hang a left on main. Then read this tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
    Bookmark Topic Watch Topic
  • New Topic