lunedì 12 dicembre 2011

EJB - Stateful session bean and timeout

This article well explains how you can set the timeout for a stateful session bean in JBoss:
http://www.mastertheboss.com/jboss-application-server/47-ejb-session-beans-.html?start=1

HOW DO YOU CONTROL THE TIMEOUT PERIOD ?

Stateful session beans have configurable timeout values which can control the amount of time a bean can remain idle prior to passivation or removal. Notice the @org.jboss.annotation.ejb.cache.simple.CacheConfig annotation. The idleTimeoutSeconds parameter configures the amount of idle time before the bean is passivated and the removalTimeoutSeconds configures the amount of idle time before the bean is permanently removed. For example, in order to set the timeout to 300 seconds:
@CacheConfig (idleTimeoutSeconds=300)

If the timeout is reached and you use the bean, the exception thrown is:


javax.ejb.NoSuchEJBException: Could not find stateful bean: am203n-6zhbku-gw3ysx5p-1-gw3yw2kw-dg

domenica 11 dicembre 2011

JBoss and cron job

If your application needs to run a cron style job, Quartz Scheduler is best solution I found.

In JBoss (6.x) it is already in the environment and can be used within a Message driven bean.

My application generates a lot of "volatile" data that have to be removed from the database when it is old or it is already processed and re-aggregated.


@MessageDriven(activationConfig =
{@ActivationConfigProperty(propertyName = "cronTrigger", propertyValue = "0,30 * * ? * *")})
@ResourceAdapter("quartz-ra.rar")
public class CreanerJob implements Job {

    public void execute(JobExecutionContext arg0) {
          System.out.println("JOB");
    }

}