Hmm ... not sure if this is possible, but how could you grab the caller's class name (and, ideally, the method name) in Java if you are working in a separate thread? I want to unload the class name received in a separate thread (so as not to block the UI thread when I do as 100+ registration operations per second).
eg:
class Main {
public void callerMethod() {
Thread.currentThread().getStackTrace()[2].getMethodName();
new Thread(new Runnable() {
@Override
public void run() {
new SecondObject().iWantToKnowMyCaller();
}
}).start();
}
}
class SecondObject {
public void iWantToKnowMyCaller() {
}
}
Usage example: I am recording a lot of data, and I do not want to block the main stream at all. some of the logs can be fast and small data, but some of them can record a lot of things. the problem is also that right now, as the code is written, callerMethod()there are about 600 input points, so refactoring will be a rather difficult task.
ALTERNATIVES:
, Thread.currentThread().getStackTrace()[2].getMethodName(); 5 , .