• Post Reply Bookmark Topic Watch Topic
  • New Topic

Wait method (multithreading) currentmethod  RSS feed

 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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()???
 
Marshal
Posts: 58424
178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Posts: 58424
178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh . . . I hadn't finished my post yet.

Where is currentMethod() from? I have never heard of it.
 
author
Marshal
Posts: 23439
138
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
 
Campbell Ritchie
Marshal
Posts: 58424
178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That sounds likely, Henry. Thank you.
 
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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?
 
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah, That os more precise answer
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!