• 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

help

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
is there anybody explain the join() method of the Thread class?
does the Thread class has a method called synchronized()? if it does,can you explain it to me?
thank you very much!
 
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If a thread encounters
aThread.join();
waits for aThread to die before executing the instruction after aThread.join();
In the API for Thread you can check that there is no such method. However you can synchronize a block of code within a method with:
.
.
.
synchronized(lockObject) {
//block to execute only for the tread owner of
//lockObject
}
.
.
.
A thread becomes owner of lockObject via executing a piece of code guarded by a synchronized command on lockObject, like the previous one, but it can only do it if the lockObject is not already grabbed. Because this would mean that a thread is already executing as piece of code that can not be executed simoultaneasly with a piece of code guarded by the same lock.
Did I messed up the thing?
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
join() is an API in Thread class.
Its Function : This method causes the current Thread to wait until this thread is no longer alive.
There is no synchronized method in Thread class but its a keyword in Java language. This keyword is used to guard the values of shared variables between different Threads.
 
They worship nothing. They say it's because nothing lasts forever. Like this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic