我有一个RecursiveTask
的子类,它包含一个Runnable
对象,应该执行它。问题是run方法中的代码永远不会到达,尽管我使用ForkJoinPool.execute
为了不阻止主线程。
public class test {
public static void main(String[] args) {
Runnable r = new Runnable() {
@Override
public void run() {
Display.getDefault().syncExec(new Runnable() {
@Override
public void run() {
System.out.println("lo");
}
});
}
};
ATLockTask t = new ATLockTask();
t.runnable = r;
new ForkJoinPool().execute(t);
}
}
public class ATLockTask extends RecursiveTask<Object>{
public Runnable runnable;
@Override
protected Object compute() {
try {
runnable.run();
} catch (Exception e) {
logger.catching(e);
}
return null;
}
}