• Post Reply Bookmark Topic Watch Topic
  • New Topic

How Interrupt() method is working in Thread  RSS feed

 
Kishor Joshi
Ranch Hand
Posts: 674
  • Mark post as helpful
  • send pies
  • 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
 
Knute Snortum
Sheriff
Posts: 4274
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Thanks knute
after again review that ref link

Now I understand it
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • 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: 4274
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • 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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!