user509755
user509755

Reputation: 2981

how to implement asynchronous work in java

I have one java program which process some business data and have to return response. But as part of backing up those data, I want to implement another method where it delivers that data to that method and asynchonously back up so that client does not have to wait for that backup operation to finish. Can someone suggest the better way to implement this? We are hitting more then 100 req/s and all the data processed needs to be backed up too.

Upvotes: 0

Views: 213

Answers (4)

Adam Gent
Adam Gent

Reputation: 49075

It sounds like you need to seriously consider using some message queue technology like JMS (Hornet) or AMQP (RabbitMQ).

@Async is nice for small chores but it does not scale and neither does a plain ExecutorService. Not to mention your problem even sounds more like a message problem and not a simple task execution (backup and client notification). MQ theory/practice/implementation requires some reading so I recommend you look at Spring AMQP/JMS and general message queue documentation.

In terms of notifying the client take a look at the new spring mvc DeferredResult.

Upvotes: 0

Juned Ahsan
Juned Ahsan

Reputation: 68715

Spring 3.0 @Async allows you to run a task asynchronously. Follow this link to learn more about Spring Asynch task usage:

http://java-success.blogspot.in/2013/05/asynchronous-processiong-with-spring.html

Upvotes: 0

CuriousMind
CuriousMind

Reputation: 3173

You should make use of java.util.concurrent.ExecutorService to implement such functionality. It will give you much finer control over thread pool size and other aspects like timeout and wait.

Upvotes: 0

upog
upog

Reputation: 5521

I guess you can make use of java.util.concurrent.ExecutorService

Upvotes: 1

Related Questions