• 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
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Explain the output->thread interruption

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


It says it will print false on the standard output.
 
Ranch Hand
Posts: 63
Mac OS X jQuery Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Rituka,

Your answer can be found here.

"...catching InterruptedException clears the thread's interrupted status..."

--eduardo
 
Rituka Jaiswal
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can anyone explain in more detail, still unable to understand fully..
Why false was printed on the console?
 
Ranch Hand
Posts: 115
Firefox Browser Notepad Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rituka Jaiswal wrote:Can anyone explain in more detail, still unable to understand fully..
Why false was printed on the console?



First you've to use code tag else noone help you
 
Eduardo Mineo
Ranch Hand
Posts: 63
Mac OS X jQuery Java
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Rituka, what they are trying to tell you is to use a tag code around your code. You can do it just selecting the code and pressing the "code" button right above the message editor. So, the resulting code will be like this:



Nice, ahn?

Anyway, have your read a lot about threading? It's quite hard to understand when you're beginning and it will help you to understand what is going on.

You must know there is no way to stop a thread from running. When you call interrupt() method, you are saying "Please, Mr. Thread, stop from running". Technically, it's done by putting an internal flag in that thread telling it is interrupted, almost as you have called an imaginary setter method setInterrupted(true). So, the impact is every blocking method will immediately throw an exception. If there was no catch, the run() would be interrupted, but since you have catch the exception, your thread is not interrupted anymore. You have put the thread back into life and there is no reason to interrupted() return true. Therefore, when you catch an InterruptedException, you are calling an imaginary setter method setInterrupted(false) because your thread is alive again.

--eduardo
 
Rituka Jaiswal
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hey thanks eduardo, I get it now..
 
Ranch Hand
Posts: 115
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Mr. Eduardo Mineo thanks for answer..........
 
ice is for people that are not already cool. Chill with this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic