• 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Threads: suspend/resume and join

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


ANs:"in run" can you explain how
I know as suspend() and resume() are not in use lately ,how will I get output as "in run last run".

2:

Can anyone explain join() and how it works, I had read Books but not able to get much please explain?

EDIT by mw: Added much-needed Code Tags. Please use these in the future. Also, made the subject line more descriptive than simply "Threads."
[ January 22, 2007: Message edited by: marc weber ]
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, it's a bit stronger than "not in use lately." These methods are deprecated because suspend is deadlock prone, and resume is only for use with suspend. For details, see Java Thread Primitive Deprecation, which illustrates how to use wait and notify instead.

The join method delays execution of the calling thread until the indicated thread completes. In this case, the main thread is "joined" to t1, which means the call to t2.start() and the println of "End" will not execute until t1 completes. Comment out the join line and note the difference in output.
 
author
Posts: 23919
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

Originally posted by marc weber:
These methods are deprecated because suspend is deadlock prone, and resume is only for use with suspend. For details, see Java Thread Primitive Deprecation, which illustrates how to use wait and notify instead.



While I agree with Marc, that the suspend() and resume() methods, can deadlock, that is not the cause in this example.

In the example, you are causing the "boo" thread to suspend itself, by having it call the suspend() method. Then you are expecting this suspended thread to resume itself by calling the resume() method. How can a suspended thread (not running thread), call the resume() method?

Henry
 
look! it's a bird! it's a plane! It's .... a teeny tiny ad
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic