ScheduledExecutorService task pausing when going to database (via JPA)

30 Views Asked by At

In a java EE application I have one scheduledExecutorService with 2 timers on it. The first via scheduledExecutorService.scheduleAtFixRate(), the second via scheduledExecutorService.schedule(). The first will activate a runnable every 2 seconds, the second will end after 60 seconds. After the 60 seconds the scheduledExecutorService is stopped, so both timers are gone.

All is working fine with system.out statements in de runnables. But when I put a database read in the runnable of the timer on the 2 second interval the runable is activated only once and looks like to be pausing, the system.out with the read-result is not displayed and schedule is not running the runable every 2 seconds. After the 60 second, the scheduledExecutorService is stopped and after that the system.out with the result of the database read is shown.

Any idea what may be causing this behaviour?

NB: Based on google-searches I have surrounded the database-read with a try catch catching Throwable but no Throwable is catched...

At first the result of the database was not shown, but that was solved by putting @Stateless and @TransactionType in the class from with the read is actually called.

The actual functionality I try to accomplish is to have two "timers" running. One on a interval of 2 seconds, one only as a count-down max waiting time. In the 2 second intervals a database check is done to see if a certain value becomes true. If that's the case both timers need to stop and the calling program may continue. If the certain value stays false all the time the calling program may continue if the time of the count-down is done.

0

There are 0 best solutions below