DecisionTaskTimedOut使用@Asynchronous注释时

时间:2014-10-28 06:41:20

标签: amazon-web-services amazon-swf

我有两组需要并行执行的活动。成功完成后,我想执行另一组活动。我使用了Task,它正在运行。但是,在使用@Asynchronous注释后,我得到DecisionTaskTimedOut并且没有任何活动开始执行。我的aspectj配置正常工作,因为我可以在目标中看到以下类:

AsyncWorkflowImpl $ AjcClosure1.class

AsyncWorkflowImpl $ AjcClosure3.class

AsyncWorkflowImpl $ AjcClosure5.class

异步版

 public class AsyncWorkflowImpl implements AsyncWorkflow{

        private AsyncActivitiesClient activitiesClient = new AsyncActivitiesClientImpl();
        private Async2ActivitiesClient activitiesClient2 = new Async2ActivitiesClientImpl();

        @Override
        public void executeActivity() {

            Promise<Integer> intermediateRes = null;
            Promise<Integer> intermediateRes2 = null;
            for(int i=0; i<5; i++){
                intermediateRes = testIntermediate(Promise.asPromise(i), intermediateRes);
            }
            for(int i=0; i<5; i++){
                intermediateRes2 = testIntermediate2(Promise.asPromise(i), intermediateRes2);
            }
            test(intermediateRes,intermediateRes2);
        }

        @Asynchronous
        public Promise<Integer> testIntermediate(final Promise<Integer> i, Promise<Integer> res){

            return  activitiesClient.testAct1(i); 
        }

        @Asynchronous
        public Promise<Integer> testIntermediate2(final Promise<Integer> i, Promise<Integer> res){
            return  activitiesClient2.testAct1(i); 
        }

        @Asynchronous
        public void test(final Promise<Integer> res, final Promise<Integer> res2){

            activitiesClient.testAct2();
        }

    }

任务版本

public class AsyncWorkflowImpl implements AsyncWorkflow{

    private AsyncActivitiesClient activitiesClient = new AsyncActivitiesClientImpl();
    private Async2ActivitiesClient activitiesClient2 = new Async2ActivitiesClientImpl();

    @Override
    public void executeActivity() {

        Promise<Integer> intermediateRes = null;
        Promise<Integer> intermediateRes2 = null;
        Settable<Integer> finalRes = new Settable<Integer>();
        Settable<Integer> finalRes2 = new Settable<Integer>();
        for(int i=0; i<5; i++){
            intermediateRes = testIntermediate(i, intermediateRes);
        }
        for(int i=0; i<5; i++){
            intermediateRes2 = testIntermediate2(i, intermediateRes2);
        }
        finalRes.chain(intermediateRes);
        finalRes2.chain(intermediateRes2);
        test(finalRes,finalRes2);
    }

    public Promise<Integer> testIntermediate(final Integer i, Promise<Integer> res){
        final Settable<Integer> tempRes = new Settable<Integer>();
        new Task(res){
            @Override
            protected void doExecute() throws Throwable {

                tempRes.chain(activitiesClient.testAct1(i)); 
            }
        };
        return tempRes;
    }

    public Promise<Integer> testIntermediate2(final Integer i, Promise<Integer> res){
        final Settable<Integer> tempRes = new Settable<Integer>();
        new Task(res){
            @Override
            protected void doExecute() throws Throwable {

                tempRes.chain(activitiesClient2.testAct1(i)); 
            }
        };
        return tempRes;
    }

    public void test(final Promise<Integer> res, final Promise<Integer> res2){

        new Task(res, res2){
            @Override
            protected void doExecute() throws Throwable {

                activitiesClient.testAct2();
            }
        };
    }
}

aspectj编织有问题吗?任何建议都受到高度赞赏。

1 个答案:

答案 0 :(得分:2)

当扩展类型为Promise的所有参数都准备就绪时,将执行@Asynchronous方法。由于 res 参数从未就绪,因此永远不会执行@Asynchronous方法。解决方案是使用@NoWait注释这些参数,以告知框架不应该等待这些参数。

解决出现的工作流程的最佳方法&#34;卡住&#34;通过查看他们的异步堆栈跟踪&#34;包含所有未完成任务的异步堆栈跟踪。使用WorkflowExecutionFlowThreadDumper发出这样的痕迹。