Timer creates multiple timer instances

This is a real simple problem, I think, but I can’t understand why this is happening. I have an implementation of an EJB timer that uses the @Singleton annotation, i.e. a single timer.

I ran it every 5 minutes. The code looks something like this:

@Singleton @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED) public class Scheduler { private static final double timerVar = Math.random() * 33; static Logger logger = Logger.getLogger("Scheduler"); @Schedule(second = "*", minute = "*/5", hour = "*", persistent = true) public void doWork() { logger.log(Level.INFO, "timer value for this session : " + timerVar); } } 

When the process starts, it runs 10 instances of the scheduler simultaneously in the interval of 1 s, i.e.

 (EJB default - 1) (EJB default - 2) (EJB default - 3) (EJB default - 4) 

etc. When I do a long operation inside the code, (EJB default - 1) not complete and when (EJB default - 2) tries to execute, it gives me an error message:

JBAS014373: EJB 3.1 PFD2 4.8.5.5.1 parallel access timeout on org.jboss.invocation.InterceptorContext$Invocation@1b83ad52 - could not get a lock within 5000 MILLION>

First, how can I avoid running multiple instances of the EJB scheduler at the same time? Secondly, what is the deal with "failed to get a lock within 5000MILLISECONDS" and how can I avoid it?

For the timeout error that I get, I found that there are a lot of tickets in the JBOSS queue, as mentioned here .


EDIT

Added code to last comment to read:

@ Tushar-46835, could you tell us about your decision, maybe show us a fragment of what you did? - rtcarlson Oct 2 '14 at 8:12

@rtcarlson: Here is the code snippet that fixed my problems:

  @Resource TimerService timerService; @Schedule(persistent = false, minute = "/30", hour = "") public void checkQueueState() { dt = new DataAccessFactory(); excvo = dt.canExecute(); dt = null; available = excvo.isExecuteReady(); if (available) { timerService.createSingleActionTimer(new Date(), new TimerConfig(null, false)); } } @Timeout private void generateReport(Timer timer) { logger.info("!!--timeout invoked here " + new Date()); } 
+7
java java-ee jboss ejb-timer
source share
1 answer

First, how can I avoid running multiple instances of the EJB scheduler at a time?

You create persistent timers. Thus, after the specified interval, he will create new ones and put them in the queue, waiting for the previous one to complete execution.

I assume that after restarting, all timers installed in the queue have a timeout, and the server will create multiple instances, since they are persistent.

Secondly, what is the deal with "it is impossible to get a lock inside 5000MILLISECONDS" and how can I avoid it?

This is singleton, all methods have a default lock, so only one thread will execute at a time. Therefore, others will get a timeout exception / cannot get a lock, etc., As you said, there is a lengthy process.

+6
source share

All Articles