wsyy
asked on
How to find out a Java thread name
Hi,
I would like to print the thread caller's names after the threads start. To be more clear, I have three code snippets attached. The first basically calls the run() function to run which in turn calls the simulate() function.
I would like to print in the simulate() which instance, ts or ts1, is call the function of run().
Thanks.
I would like to print the thread caller's names after the threads start. To be more clear, I have three code snippets attached. The first basically calls the run() function to run which in turn calls the simulate() function.
I would like to print in the simulate() which instance, ts or ts1, is call the function of run().
Thanks.
private void Simulate(){
System.out.println(Thread.currentThread().getName()+" starting...");
....
}
public class TestThreads {
public static void main(String[] args){
for(int i=0; i<200; i++){
YYTConfiguration yytConf=new YYTConfiguration();
MyThread ts=new MyThread(yytConf.getConfiguration());
MyThread ts1=new MyThread(yytConf.getConfiguration());
ts.run();
ts1.run();
}
}
}
public void run(){
Simulate();
}
The best way is to set the thread name explicitly first, before using the code you've got
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
btw you're not starting a new thread, you need to call start() to do that
wsyy, can you say why you accepted that answer? It answers a different question
> wsyy, can you say why you accepted that answer? It answers a different question
No it doesn't. I don't think you read the question properly
No it doesn't. I don't think you read the question properly
?