我有三组。前两组可以并行执行。第三组只有在第一组和第二组执行成功后才能执行。问题是它们都是随机执行的。没有这样的编排。
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(Promise.asPromise(i), intermediateRes);
}
for(int i=0; i<5; i++){
intermediateRes2 = testIntermediate2(Promise.asPromise(i), intermediateRes2);
}
finalRes.chain(intermediateRes);
finalRes2.chain(intermediateRes2);
List<Promise<Integer>> promiseList = new ArrayList<Promise<Integer>>();
promiseList.add(finalRes);
promiseList.add(finalRes2);
test(promiseList);
}
@Asynchronous
public Promise<Integer> testIntermediate(Promise<Integer> i, Promise<Integer> res){
return activitiesClient.testAct1(i);
}
@Asynchronous
public Promise<Integer> testIntermediate2(Promise<Integer> i, Promise<Integer> res){
return activitiesClient2.testAct1(i);
}
@Asynchronous
public void test(@Wait List<Promise<Integer>> promiseList){
activitiesClient.testAct2();
}
}
包:com.myco.test
src/main/resources/aop.xml
<aspectj>
<aspects>
<!-- declare two existing aspects to the weaver -->
<aspect name="com.amazonaws.services.simpleworkflow.flow.aspectj.AsynchronousAspect"/>
<aspect name="com.amazonaws.services.simpleworkflow.flow.aspectj.ExponentialRetryAspect"/>
</aspects>
<weaver options="-verbose">
<include within="com.myco.test..*"/>
</weaver>
</aspectj>
pom.xml
<!-- language: lang-xml -->
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.6.11</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-flow-build-tools</artifactId>
<version>1.8.10.2</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk</artifactId>
<version>1.8.10.2</version>
</dependency>
<dependency>
<groupId>org.freemarker</groupId>
<artifactId>freemarker</artifactId>
<version>2.3.18</version>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.3</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-io</artifactId>
<version>1.3.2</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.0.13</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.6</version>
</dependency>
<dependency>
<groupId>commons-dbutils</groupId>
<artifactId>commons-dbutils</artifactId>
<version>1.6</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
<scope>compile</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<configuration>
<sources>
<source>
<basedir>src/main/java</basedir>
<includes>
<include>**/*.java</include>
</includes>
</source>
<source>
<basedir>${project.build.directory}/generated-sources</basedir>
<includes>
<include>**/*.java</include>
</includes>
</source>
</sources>
<aspectLibraries>
<aspectLibrary>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk</artifactId>
</aspectLibrary>
</aspectLibraries>
</configuration>
</plugin>
</plugins>
</build>
默认虚拟机参数:
-javaagent:C:\aspectj1.7\lib\aspectjweaver.jar