Proposed API for JEP 259: Stack-Walking API

Peter Levart peter.levart at gmail.com
Tue Nov 17 22:09:42 UTC 2015



On 11/17/2015 10:13 PM, Peter Levart wrote:
>
>> I will keep returning the thread’s entry point case to return the class of the runnable instead of returning Thread.class.
>
> But (as described in my other message), Runnable::run is not an entry 
> point. Thread::run is. And Thread::run (a Java method) delegates to 
> Runnable::run. So in this case Thread.class will be returned as a 
> normal caller (which it really is). Are you thinking of detecting this 
> situation and special-casing it?
>
> Regards, Peter


I think this is not a good idea.

1st it's difficult to reliably detect this situation. For example:

Runnable r = ...;

....

new Thread(r).start();

vs.

class MyThread extends Thread {
     MyThread(Runnable r) {
         super(r);
     }
     @Override public void run() {
         // .. some setup
         super.run();
     }
}

new MyThread(r).start();


2nd why would this be limited to Thread delegate? What about:

Executable exe = Executables.newFixedThreadPool(...);

exe.execute(r);

...and how would you detect that?



I think that calling getCallerClass() from implementation of 
Runnable::run should expect it to return a system class. It may be 
Thread.class or ThreadPoolExecutor$Worker.class or anything actually.


Regards, Peter




More information about the core-libs-dev mailing list