What is the correct way to run a scheduled task on the Java EE 5 (JBoss) platform?

I need to run a simple scheduled task that starts every 200 ms and does something simple.

Is Executors.newSingleThreadScheduledExecutor() right way to get the scheduled executor service on JBoss?

They say that spawning unmanaged threads on the Java EE platform is not recommended. It seems that this thread will be uncontrollable.

On the other hand, I do not want to declare MBeans, etc. for such a simple thing.

Edit

There is something like org.jboss.resource.work.JBossWorkManager , but I can not find an example of the planned work.

+6
source share
1 answer

Calling Executors.newSingleThreadScheduledExecutor() not scary, but it's best to avoid it in EE containers. In Java EE 5, use a 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, the @Schedule annotation will be convenient for @Schedule .

+4
source

Source: https://habr.com/ru/post/923646/


All Articles