Reputation: 4973
I have an async task that performs database operations. This may take many minutes.
public void doSomeStuff() {
// 10 minutes of database magic
}
Due to possible concurrency problems on the database side, there must be only one asynchronous execution of this method at the same time (like a singleton). Furthermore if the method is already running, the next call shall not be discarded, but rememberered and executed when the previous call finishes. Just like a queue.
I've researched the @Asynchronous
and @ConcurrencyManagement(...)
annotations, however they don't seem to provide the required control.
How can I achieve this in JavaEE 7 with the JBoss EAP 6 (+JSF)?
Upvotes: 0
Views: 187
Reputation: 2271
You could use a @Stateless
bean with an @Asynchronous
method.
Then you could set the thread pool used by the bean with the annotation @Pool(<pool name>)
. If you limit the pool size to 1, you have what you need.
Upvotes: 1