I need to run a simple scheduled task that will start every 200ms and do something simple.
Is Executors.newSingleThreadScheduledExecutor()
the proper way of obtaining scheduled executor service on JBoss?
It is said that spawning unmanaged threads on Java EE platform is not recommended. It seems that this thread will be an unmanaged one.
On the other hand I don't want to declare MBeans etc. for such simple thing.
Edit
There is something as org.jboss.resource.work.JBossWorkManager
but I can't find an example of scheduled work.
Calling Executors.newSingleThreadScheduledExecutor()
is not terrible, but better avoid it in EE containers. In Java EE 5 use TimeoutService
:
@Stateless
public class TimerSessionBean implements TimerSession {
@Resource
TimerService timerService;
public void startTimer() {
Timer timer = timerService.createTimer(200, "Created new timer");
}
@Timeout
public void timeout(Timer timer) {
logger.info("Timeout occurred");
}
}
In Java EE 6 you have handy @Schedule
annotation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With