Porblem in Ejb3 using TimerService with @Singleton and @Management
sbutt Mar 21, 2014 7:55 AMHi All,
I am trying to understand an old code written by a colleague who has left the company now.
The problem is about calling a start() method, which should then initialize a timeerservice and further invokes a method.
The code was presumably working fine earlier on jboss 5, but since we have now migrated to jboss 6, it does not seems to work.
The EJB is as follows:
package com.abc.potsdam.middleware.cache; import java.util.StringTokenizer; import javax.annotation.Resource; import javax.ejb.EJB; import javax.ejb.SessionContext; import javax.ejb.Singleton; import javax.ejb.Stateless; import javax.ejb.Timeout; import javax.ejb.Timer; import javax.ejb.TimerService; import javax.ejb.TransactionAttribute; import javax.ejb.TransactionAttributeType; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.jboss.annotation.ejb.Service; import com.traveltainment.potsdam.common.configuration.ConfigService; @Singleton @Stateless @TransactionAttribute(TransactionAttributeType.NEVER) public class CacheLoaderBean implements CacheLoader, CacheLoaderManagement { private Log log = LogFactory.getLog(this.getClass()); @EJB(mappedName = "/ConfigServiceBean/local") ConfigService configService; @EJB DroolsSession droolsSession; @Resource private SessionContext sessionContext; /** * after 10000 ms starting of loading persistence units * * @param timer */ @Timeout public void startTimeout(Timer timer) { loadPersistenceUnitsToCache(); } public void loadPersistenceUnitsToCache() { String persistenceUnits = configService .getProperty("AvailablePersistenceUnits"); log.info("reloading persistence units: " + persistenceUnits); StringTokenizer stringTokenizer = new StringTokenizer(persistenceUnits, ","); while (stringTokenizer.hasMoreTokens()) { String persistenceUnitName = stringTokenizer.nextToken(); droolsSession.initSession(persistenceUnitName); } } public void start() { // create timer for 10000 ms to start loading cache TimerService timerService = sessionContext.getTimerService(); Timer timer = timerService.createTimer(10000, "cache loading timer"); } }
The imported interfaces are:
package com.abc.potsdam.middleware.cache; import org.jboss.ejb3.annotation.Management; @Management public interface CacheLoaderManagement { public void loadPersistenceUnitsToCache(); public void start(); }
package com.abc.potsdam.middleware.cache; import javax.ejb.Local; import org.jboss.annotation.ejb.Management; @Local public interface CacheLoader { public void loadPersistenceUnitsToCache(); }
The problem is that in my implementation bean, I don't see the start() method ever getting executed. If it is to be invoked via JMX-Console then also I am a bit unaware as to how I can do that?
Since the start method never gets executed, the rest of the functionality is also never invoked.
I have done a bit of research on the topic, and found out at some threads that probably @Singleton and @Management have some issues together when using jboss 6?
The compilation is all done fine, it is only then the code never gets executed and I don't see the log messages appearing.
Could some please give me some pointers as to how I can set a timer for my scenario here?
Thanks.