当前位置: 动力学知识库 > 问答 > 编程问答 >

java - Spring - concurrency task

问题描述:

We are using spring in our web application.

Consider the following example:

public ResultDTO getAllHappyFaces(Face[] faces) {

ResultDTO result = new ResultDTO();

for (int i = 0; i < faces.length; i++) {

if (calculateIfHappyFace(faces[i]))

result.add(i);

}

return result;

}

Now, we would like to make this process concurrent.

Whats our best way of doing that using spring's standard module for executing multithreaded tasks?

Thanks

网友答案:

You haver to use @Async annotation

     @Async
     void doSomething() {
        // this will be executed asynchronously
     }

Look the documentation of Spring http://docs.spring.io/spring/docs/3.0.x/spring-framework-reference/html/scheduling.html

分享给朋友:
您可能感兴趣的文章:
随机阅读: