Igen, ezt én is megtaláltam, de vagy kell még valami, vagy Glassfish alatt másképp kell.
@Singleton
@LocalBean
@Startup
public class MonitorSingleton implements MonitorSingletonLocal {
...
@Resource
TimerService timerService;
private long pollingTime;
/**
* Default constructor.
*/
public MonitorSingleton() {
System.out.println("Starting MonitorSingleton"); //$NON-NLS-1$
try {
...
this.startTimer();
}
catch (Exception e) {
log.error(e);
}
}
...
@Timeout
protected void background() {
log.debug("Start polling"); //$NON-NLS-1$
try {
...
}
catch (Exception e) {
log.error(e);
}
finally{
this.startTimer();
}
}
private void startTimer() {
@SuppressWarnings("unused")
Timer timer = this.timerService.createTimer(this.pollingTime, "Restart"); //$NON-NLS-1$
}