aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes thread Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "thread " Watch "thread " New topic
Author

thread

smily sharma
Greenhorn

Joined: Jan 04, 2008
Posts: 1
hi
have a look this is an interesting q.actualy, the answer just struck my mind, while posting this q on the forum.
hope you would like it.

o/p T1T1T3

----- indenting repaired, Bu.
[ January 08, 2008: Message edited by: Burkhard Hassel ]
Ian Edwards
Ranch Hand

Joined: Aug 14, 2006
Posts: 107
It took a minute to unravel what was going on there.

Calling the run() method doesn't start the thread which is why calling the run() method on A prints out the thread name of thread T1 on the first 2 occasions.
Burkhard Hassel
Ranch Hand

Joined: Aug 25, 2006
Posts: 1274
Hi ranchers,

as Ian said: The thread with the // doubt in the line is actually never started.
It only invokes the run method without starting as a seperate thread. And since there is no seperate thread started with "T2" as name, you'll never read this.


Something else, "smily sharma" !

Please have a look into your private messages by clicking the "My Private Messages" link near the top of this page.

Yours,
Bu.


all events occur in real time
Arjun Cheng
Greenhorn

Joined: Jan 08, 2008
Posts: 13
I just runed the program. I got T1T2T3 as I thought.
Christian Hans
Greenhorn

Joined: Jan 08, 2008
Posts: 2
I'm not sure why the line wouldn't start a new thread, as was previously mentioned. Calling a Java thread's start method initializes a thread and calls its run() method. If the line were to read , the output would be T1T1T3. As was written in the original post, the code should print T1T2T3.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: thread