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

Thread java se 6

 
Greenhorn
Posts: 29
Mac Java ME Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

i don't knew why it affiche 999999 pleaz somme one can explain for me that code
 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HI Adil,

I tried to help you but I can understand the example!

There is not object that is doing a "notify()" or "notifiAll()" on "thread" var.
I can not understant how line 20 is reached!

Please, to someone! ;-)
 
Ranch Hand
Posts: 226
Eclipse IDE Firefox Browser Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Alam Ameghino wrote:HI Adil,

I tried to help you but I can understand the example!

There is not object that is doing a "notify()" or "notifiAll()" on "thread" var.
I can not understant how line 20 is reached!

Please, to someone! ;-)



It's a super tricky question.
However it yields that result because when the thread job finishes its run method "dies"; once the thread is dead all the locks get released automatically.
Source: I had already asked the question in some forum (I don't remember where) and that's the answer I got.
 
author
Posts: 23951
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

Alam Ameghino wrote:
I tried to help you but I can understand the example!

There is not object that is doing a "notify()" or "notifiAll()" on "thread" var.
I can not understant how line 20 is reached!

Please, to someone! ;-)




Simply, it is a conflict of resources. The example is using an instance for notifications that is already in use by the library.

Take a look at the java.lang.Thread javadoc, specifically for the join() method. The java library uses the thread instance for the join() method -- threads that call join() will wait() on the thread object, and notifications will be sent when the thread terminates.

Work-around: Don't use the Thread instance for notifications.

Henry
 
Alam Ameghino
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
After Henrry and Nick's comments, I can understand the idea perfectly. A lot of Thanks to both!

I take the idea:

...when the thread job finishes its run method "dies"; once the thread is dead all the locks get released automatically


I take this idea despite I don't know where it happen in the sources!

Concerning the comment's Henrry.. I read the API Thread, in special this piece about join() method:

This implementation uses a loop of this.wait calls conditioned on this.isAlive. As a thread terminates the this.notifyAll method is invoked. It is recommended that applications not use wait, notify, or notifyAll on Thread instances.



But, What role play the join() method in this example? There isn't join() method here, or I am not seeing it!
 
Henry Wong
author
Posts: 23951
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

Alam Ameghino wrote:
Concerning the comment's Henrry.. I read the API Thread, in special this piece about join() method:

This implementation uses a loop of this.wait calls conditioned on this.isAlive. As a thread terminates the this.notifyAll method is invoked. It is recommended that applications not use wait, notify, or notifyAll on Thread instances.



But, What role play the join() method in this example? There isn't join() method here, or I am not seeing it!



The thread cleanup code will call notifyAll() (while holding the lock, and after it has marked the thread as no longer alive) in order to wake up any threads executing the join() method. It doesn't actually check to see if there are any threads calling the join() method. If there are no threads joining, then those notifications will simply be discarded.

And in the case of this example, if there are threads waiting on the thread object for other reasons, they will get the notification too.

Henry
 
Alam Ameghino
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Henry, I will never tire of saying THANKS!
Henry, nunca me voy a cansar de darte las GRACIAS!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic