Run method not working inside ForkJoinTask

2019-09-15 12:26发布

I have a sub class of RecursiveTask which contains a Runnable object and should execute it.The problem is that the code inside the run method never gets reached although I use ForkJoinPool.execute in order to not block the main thread.

 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条回答
登录 后发表回答