java - How to access thread objects inside custom threadpool executor's methods? -


i want access data inside runnable objects have in custom threadpool executor. if tried access in before/after execute methods getting class cast exception. how resolve scenario.

public class mythread implements runnable  {   string key;    public void run(){ /* */}   }  public class myexecutor extends threadpoolexecutor {    @override   protected void beforeexecute(thread paramthread, runnable paramrunnable)   {              mythread mt = (mt)paramrunnable;     }    @override   protected void afterexecute(runnable paramrunnable, throwable paramthrowable)   {        mythread mt = (mt)paramrunnable;      /* need access "key" inside mythread */      } 

if classcastexception means pass in thread implementations not mythread or subclass of mythread myexecutor. in order fix instanceof check before casting.

public class myexecutor extends threadpoolexecutor {    @override   protected void beforeexecute(thread paramthread, runnable paramrunnable)   {          if(paramrunnable instanceof mythread) {              mythread mt = (mythread)paramrunnable;           }    }    @override   protected void afterexecute(runnable paramrunnable, throwable paramthrowable)   {        if(paramrunnable instanceof mythread) {            mythread mt = (mythread)paramrunnable;         }        /* need access "key" inside mythread */      } 

Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

[C++][SFML 2.2] Strange Performance Issues - Moving Mouse Lowers CPU Usage -

ios - Possible to get UIButton sizeThatFits to work? -