wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Wait method (multithreading) currentmethod Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Wait method (multithreading) currentmethod" Watch "Wait method (multithreading) currentmethod" New topic
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: 37936
    
  22
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: 37936
    
  22
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: 18508
    
  40

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: 37936
    
  22
That sounds likely, Henry. Thank you.
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4165
    
  21

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: 119
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: 4165
    
  21

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: 119
Yeah, That os more precise answer
 
 
subject: Wait method (multithreading) currentmethod
 
Similar Threads
KB Chapter 9 Question 9
Conditions in Synchronized Blocks
synchrinized code doubt
where is the notify?
IllegalMonitorStateException