我想访问自定义线程池执行程序中的可运行对象内的数据。如果我尝试访问之前/之后的执行方法,我会得到类转换异常。我该如何解决这种情况。
public class MyThread implements Runnable
{
String key;
public void run(){ /* Do something */}
}
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 to access "key" inside MyThread */
}