开发者

What's the effect on a second request of calling Thread.currentThread().sleep(2000) in a Spring MVC request handler?

开发者 https://www.devze.com 2023-04-07 11:36 出处:网络
I need to wait for a condition in a Spring MVC request handler while I call a third party service to update some entities for a user.

I need to wait for a condition in a Spring MVC request handler while I call a third party service to update some entities for a user.

The wait averages about 2 seconds.

I'm calling Thread.sleep to allow the 开发者_开发技巧remote call to complete and for the entities to be updated in the database:

Thread.currentThread().sleep(2000);         

After this, I retrieve the updated models from the database and display the view.

However, what will be the effect on parallel requests that arrive for processing at this controller/request handler?

Will parallel requests also experience a wait?

Or will they be spawned off into separate threads and so not be affected by the delay experienced by the current request?


What are doing may work sometimes, but it is not a reliable solution.

The Java Future interface, along with a configured ExecutorService allows you to begin some operation and have one or more threads wait until the result is ready (or optionally until a certain amount of time has passed).

You can find documentation for it here: http://download.oracle.com/javase/6/docs/api/java/util/concurrent/Future.html

0

精彩评论

暂无评论...
验证码 换一张
取 消