Reputation: 69
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.
Upvotes: -1
Views: 92
Reputation: 3593
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.
Upvotes: 0