If a multi threaded Java program has started numerous number
of threads, at any point in time how to know which thread is
currently executing/running ?
Answers were Sorted based on User's Feedback
Answer / namita kapoor
You can check by putting following code in your program
Thread t = Thread.currentThread();
System.out.println("Current Thread: "+t);
| Is This Answer Correct ? | 36 Yes | 1 No |
Answer / ss
currentThread() method is static method, so don't need to
create the thread object to call the method..
Below is the correct way ..
Thread t=Thread.currentThread();
System.out.println(t.getName());
| Is This Answer Correct ? | 13 Yes | 0 No |
Answer / srinivas
by using currentThread() Method ,we can find which thread
is runing
| Is This Answer Correct ? | 12 Yes | 0 No |
Answer / ankush sharma
We can check the current Thread name as
Thread t= new Thread.currentThread();
System.out.println(t.getName());
| Is This Answer Correct ? | 11 Yes | 0 No |
Answer / adminraj
Check executing/running current thread by
currentThread() [Method]
public static Thread currentThread()
Find the currently executing thread.
Returns:
the currently executing thread
| Is This Answer Correct ? | 9 Yes | 0 No |
Answer / akj504
but if I want check/findout within my program itself
How do I do that ?
| Is This Answer Correct ? | 2 Yes | 8 No |
Answer / chellammal
Using Java Debugger "jdb" one gets information about
which thread currently executing threads
| Is This Answer Correct ? | 3 Yes | 14 No |
What is considered an anti pattern?
abstract class Demo { public void show() { System.out.println("Hello I am In show method of Abstract class"); } } class Sample extends Demo { public void show() { super.show(); System.out.println("Hello I am In Sample "); } } public class Test { public static void main(String[] args) { //I WANT TO CALL THE METHOD OF BASE CLASS IT IS POSSIBLE OR NOT CAN WE USE SCOPE RESOLUTION OPERATOR TO CALL OR JAVA NOT SUPPORTED THAT :: OPERATORE } }
Difference between notify() method and notifyall() method in java?
What is the Concept of Encapsulation in OOPS
What is the difference between public, private, protected, and friend access?
What is basic syntax?
What is polymorphism in java? What are the kinds of polymorphism?
What is nested interface?
Where pragma is used?
Why java uses the concept of the string literal?
What is an iterator java?
What is the meaning of nullable?