• 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 question

 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello.
here is a thread question. I don't know why the correct answer is 2. False. please Help! much appreciated.
---------------------------------
Assume that th is an instance holding a thread object. th.start() causes the thread to start running and eventually complete its
execution. The object reference by th is not accessable any more and is garbage collected when the garbage collecter runs.

1.True
2.False
-----------------
chun
 
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thread object is like any other object. The only 'special' thing about it is that you can use it to spawn asynchronous paths of execution. Once the thread finishes running, you can access any data member/method of the thread object like any other object.
Consider this example - you can create a <code>'DurationCounter' </code> object that just counts till 1000 or until it is interrupted. The counting logic is in the run method and it stores the final counted value in an attribute, say <code>durationCounted</code>. In order to make it count, you simply instantiate a Thread using this object and call the <code>DurationCounterObject.start()</code> method. Lets assume the thread completes execution either with no interruption, or with an interruption.
If you now want to findout howmuch it has counted, you can access the attribute by using - <code>DurationObject.durationCounted</code>
The point I am trying to make is, a thread object is like any other object. Hence it is also governed by usual garbage collection rules ie., like any other normal object, it can be garbage colleted ONLY IF it has no active references. Since the reference 'th' may still be active after the thread executes, the answer is false.

Hope that helps
------------------
Ajith Kallambella M.
Sun Certified Programmer for the Java�2 Platform.
 
Chun Wang
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks a lot, Ajith!
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic