This week's giveaway is in the JDBC forum.
We're giving away four copies of Java Database Connections & Transactions (e-book only) and have Marco Behler on-line!
See this thread for details.
Win a copy of Java Database Connections & Transactions (e-book only) this week in the JDBC 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 ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

Question from examlab on threads  RSS feed

 
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi ,



This is a question from examlab. It outputs Ex-B and then an exception.
Although a nice explanation is given in examlab. But i could not understand the interrupt
call on line 2.
According to me the working should be :

Line 1 should start the thread t and then doDelay should make t sleep for 1 sec.
Meanwhile main calls dodelay() which should put main to sleep.
But main should wake you before t and then call interrupt. This must make t throw
IntrruptedException and print Ex-A. Now thread t should resume and call halt() and
calling wait() should throw Exception and print Ex-B..

Please correct me if i am wrong.
 
Sheriff
Posts: 9643
42
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is a slight trick here, we actually started thread t and called interrupt on a. This is why the call to a.interrupt() didn't throw an exception. If you call t.interrupt() instead of a.interrupt(), you'll get "Ex-A" in the output...
 
ujjawal rohra
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes Ankit it works..
Thanks but i want to know that the execution which i stated is correct or not. I am having much problem in getting threads..
Please let me know
 
Ankit Garg
Sheriff
Posts: 9643
42
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes your interpretation of the flow of execution was right...
 
ujjawal rohra
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok dear thanks very much
 
You didn't tell me he was so big. Unlike this tiny ad:
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!