wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes thread Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "thread" Watch "thread" New topic
Author

thread

meeta gaur
Ranch Hand

Joined: Dec 05, 2012
Posts: 305


In run method threade name is:main
In main method thread name is:main

Don't understand where is t1 ?


My one regret in life is that I am not someone else.
- Woody Allen
Chan Ag
Bartender

Joined: Sep 06, 2012
Posts: 1000
    
  16
We don't start a thread ( as a separate task ) by invoking the run method directly on the thread object. We invoke the start() method on the thread object. The start() method is in the Thread class and it invokes the run() method we override in our implementation.

Try invoking the start method on your thread object and see what output you get?

Chan.

Edit : Since you have invoked run method directly, you have effectively not started a new thread and hence the thread that is executing the run() method is still the main thread. A thread ( a separate task ) begins when you invoke the start method on the thread object.
meeta gaur
Ranch Hand

Joined: Dec 05, 2012
Posts: 305

Oh my lord i didn't observe carefully , i thought i m calling start method but it was run.
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 7545
    
  18

meeta gaur wrote:Don't understand where is t1 ?

Did you ask for its name?

I suggest you look carefully at the docs for currentThread(), and especially its signature - although I have to admit that the doc contents themselves aren't very helpful.

Winston

Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 7545
    
  18

meeta gaur wrote:Oh my lord i didn't observe carefully , i thought i m calling start method but it was run.

Right. But it won't solve your basic problem, even if you call it right - at least, I'm pretty sure it won't.

You need to read my last post.

Winston
 
 
subject: thread
 
Similar Threads
Dan's Question : Thread
join() method
java Thread
help regarding synchronized methods
setPriority()