问题描述:

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

相关阅读:
Top