• 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
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

How Interrupt() method is working in Thread

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

I am following this article
http://docs.oracle.com/javase/tutorial/essential/concurrency/simple.html


and here is my code




I want to know How join() and interrupt() method is working on this program?


I have read above article so no refernce or link to that please.Someone please explain these two methods with reference to this program



Thanks
 
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not sure what you don't understand. interrupt() tells the thread, "Hey, stop what you're doing." join() says, "Pass control back to me."

I know you said no links, which is annoying, because I think this would help you.
 
Kishor Joshi
Ranch Hand
Posts: 674
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks knute
after again review that ref link

Now I understand it
 
author
Posts: 23958
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Knute Snortum wrote:interrupt() tells the thread, "Hey, stop what you're doing."



While true, it is a lot more complicated than that. After the other thread gets interrupted, different things can happen, depending on what it was doing when it got interrupted. Also, depending on the JVM version, there can be differences in behavior too (ex. does the OS support interruptable I/O).

Knute Snortum wrote: join() says, "Pass control back to me."



Not sure if I agree with this. I think it is more like, wait until the other thread completes its execution. After all, the thread already has "control" (meaning is executing), or else it wouldn't be able to call the join() method.

Henry
 
Knute Snortum
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Henry. I'm trying to find the balance between complete and easy to understand -- but I should always be accurate.
 
You guys haven't done this much, have ya? I suggest you study this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic