• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Why send interrupt to a thread?

 
Ranch Hand
Posts: 214
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I understand the application of the interrupt method.

But WHY would one ever call interrupt on a thread that is waiting on an object's lock?

A "real world" illustration would be much appreciated.

Regards,

Simon.
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Socket not responding...Reader not responding...
 
Ranch Hand
Posts: 1282
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually, many people ignore the why of the matter: Depends on what your target user is.
If the sole thread of execution, running both the user-interface and the program it's self, tries to open a socket or something that the operating system does not manage for the programmer - the mouse and everything else for that program is hung. To the user it appears that the program has failed, and it has from a reliability issue, because the user cannot regain control of the machine if the socket call hangs.
The correct way to do this is make a boolean variable in the class instantiated, then occsionally check that variable from another thread. The reason for this is that the only way to break the socket call is to
the socket call. The only way to interrupt it is from another Thread.

Interrupts should only be used as crisis-management.

Not for routine load-balancing.
 
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A good real time example is normally a thread sleeps for n seconds before retrying. Some times a high priority event occurs in some other thread and so the sleeping thread needs to be interrupted.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic