| Author |
Wait method (multithreading) currentmethod
|
Varun Goenka
Ranch Hand
Joined: Mar 09, 2009
Posts: 37
|
|
I have seen the wait method being called without any reference.
Even if its static (in case it is; i dont know) should you not write the class name.
Also what exactly is the currentMethod() method and when did it replace new class_name()???
|
From The Demon,
with love.
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32694
|
|
You need to check the API to find out whether it is static.
Remember what a call to a method without a . before it means, and (assuming it is an instance method) which object that is called on.
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32694
|
|
Oh . . . I hadn't finished my post yet.
Where is currentMethod() from? I have never heard of it.
|
 |
Henry Wong
author
Sheriff
Joined: Sep 28, 2004
Posts: 16695
|
|
Campbell Ritchie wrote:
Where is currentMethod() from? I have never heard of it.
Maybe the question was about the currentThread() method, which is a static method of the Thread class, that returns the Thread object of the calling thread.
Henry
|
Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32694
|
|
|
That sounds likely, Henry. Thank you.
|
 |
Steve Luke
Bartender
Joined: Jan 28, 2003
Posts: 3036
|
|
Henry Wong wrote:
Campbell Ritchie wrote:
Where is currentMethod() from? I have never heard of it.
Maybe the question was about the currentThread() method, which is a static method of the Thread class, that returns the Thread object of the calling thread.
Henry
Perhaps, but Varun, can you be more specific? Even assuming you mean Thread.currentThread(), then the following statement doesn't make sense:
Also what exactly is the Thread.currentThread() method and when did it replace new class_name()?
Can you tell us what you mean and why you think that method (currentThread() or currentMethod()) replaced creating a new object?
|
Steve
|
 |
Anil Deshpande
Ranch Hand
Joined: Jan 13, 2008
Posts: 117
|
|
Current Thread is a static method in Thread class. It returns the Thread name,priority (by default 5 i.e NORM_PRIORITY) and method name in which it was invoked.
i.e if you call method currentThread in run mthod of Thread and then start thread from the main method, answer would be like
Thread[Thread-0,5,main].
And about wait() method is not the static method.It is instance method in Object class. That is super daddy of all classes that you write in Java
|
Anil Deshpande
SCJP 1.5, SCWCD 1.5
|
 |
Steve Luke
Bartender
Joined: Jan 28, 2003
Posts: 3036
|
|
Anil Deshpande wrote:Current Thread is a static method in Thread class. It returns the Thread name,priority (by default 5 i.e NORM_PRIORITY) and method name in which it was invoked.
Not true. It returns a reference to the currently running Thread. See the API: java.lang.Thread.
i.e if you call method currentThread in run mthod of Thread and then start thread from the main method, answer would be like
Thread[Thread-0,5,main].
Which is the output for Thread#toString(). So this output is only returned when you call Thread.currentThread().toString() (or send the thread reference to some other method which does the toString() part, for example by calling System.out.println(Thread.currentThread()))
|
 |
Anil Deshpande
Ranch Hand
Joined: Jan 13, 2008
Posts: 117
|
|
|
Yeah, That os more precise answer
|
 |
 |
|
|
subject: Wait method (multithreading) currentmethod
|
|
|