using @schedule in EJB timer,not able to pass the schedule details from database

96 views Asked by At

using @schedule in EJB timer, i want to pass the schedule details from database. but it is not allowing passing values. What should i do. In @timeout also i'm not able to start the thread automatically at server start time. @Postconstruct is not working.

1

There are 1 answers

2
aschoerk On

You might have to use @Timeout, @Singleton, @Startup and @ConcurrencyManagement

@Singleton(name = "...", mappedName = "")
@Startup
@ConcurrencyManagement(ConcurrencyManagementType.BEAN)  // this is threadsafe!!!
public class .......

Inject the TimerService for configuration

@Resource
private TimerService timerService;

Inject the EntityManager for db-access

@PersistenceUnit(..)
private EntityManager entityManager

Use @Timeout instead of @Schedule

@Timeout
void timer() { .... }

Configure the timer

@PostConstruct
void postConstruct() {
   entityManager.createQuery(....);
   .
   .
   timerService.createIntervalTimer(....);
}

except usage of EntityManager, this works at our site.