在ForkJoinTask中运行方法不起作用

时间:2017-03-03 12:44:27

标签: java eclipse-plugin runnable

我有一个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;
    }
}

Thread states before entering syncExec

Thread states after entering syncExec

0 个答案:

没有答案