Timer service in ejb 3.1 - timeout call schedule

I created a simple example with the annotations @Singleton, @Schedule and @Timeout to try to solve the problem.

The scenario is this: EJB calls the validation function for every 5 seconds, and if certain conditions are met, it will create a timer for one action that will call some lengthy process in an asynchronous way. (this is a type of queue implementation type). Then he continues to check, but while the lengthy process does not start there.

Below is the code that I came up with, but this solution does not work, because it looks like the asynchronous call that I am making is actually blocking my @Schedule method.

@Singleton
@Startup
public class GenerationQueue {

    private Logger logger = Logger.getLogger(GenerationQueue.class.getName());

    private List<String> queue = new ArrayList<String>();

    private boolean available = true;

    @Resource
    TimerService timerService;

    @Schedule(persistent=true, minute="*", second="*/5", hour="*")
    public void checkQueueState() {

        logger.log(Level.INFO,"Queue state check: "+available+" size: "+queue.size()+", "+new Date());

        if (available) {

            timerService.createSingleActionTimer(new Date(), new TimerConfig(null, false));
        }

    }

    @Timeout
    private void generateReport(Timer timer) {

        logger.info("!!--timeout invoked here "+new Date());

        available = false;

        try {

            Thread.sleep(1000*60*2); // something that lasts for a bit

        } catch (Exception e) {}

        available = true;

        logger.info("New report generation complete");

    }

What am I missing here, or should I try different aproach? Any ideas are welcome :)

Glassfish 3.0.1 -

+5
1

@ConcurrencyManagement singleletons - ConcurrencyManagementType.CONTAINER @Lock LockType.WRITE. , ( generateReports) synchronized, , checkQueueState generateReport.

ConcurrencyManagement (ConcurrencyManagementType.BEAN) @Lock (LockType.READ). , , Glassfish.

, , , persistent = false, , , , checkQueueState 5 , . , , , "" .

+11

All Articles