I have an anonymous Thread object:
new Thread(new Runnable() {
@Override
public void run() {
try {
Thread.sleep(2000);
}
catch (InterruptedException e) {
}
}
}).start();
This anonymous thread is inside a loop, and will run when the conditions are met in the loop.
I wanted to know if I can obtain an instance of the running anonymous Thread object without creating a class member of type Thread and make it reference to the anonymous Thread object, so that the application won’t start the Thread object too many times in the loop.
I was thinking of using [icode]Thread.currentThread()[/icode] static method to get the instance, but the more I think of it, the more difficult it is to come up with a solution. Hm…