aspose file tools*
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


Win a copy of Spring in Action this week in the Spring forum!
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: 1021
    
  15
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: 8008
    
  22

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: 8008
    
  22

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: thread