Page 1 of 1
About Question enthuware.oce-ejbd.v6.2.429 :
Posted: Thu Apr 14, 2011 5:31 am
by ETS User
Programmatic timer creation is also valid, I can create a @Singleton with @Startup, and in its @PostConstruct I can create the timer for whatever EJB I want.
Is it not so?
Re: About Question enthuware.oce-ejbd.v6.2.429 :
Posted: Thu Apr 14, 2011 7:38 am
by admin
I am not sure if you can create a timer for another bean.
Re: About Question enthuware.oce-ejbd.v6.2.429 :
Posted: Thu Apr 14, 2011 8:01 am
by Guest
You can't, but if the EJB for which the timer is intended has a method named createTimer() { ... }, then the @PostConstuct method can invoke that method. This concludes a complete programmatic creation of a Timer.
Re: About Question enthuware.oce-ejbd.v6.2.429 :
Posted: Thu Apr 14, 2011 7:53 pm
by admin
A statement "(Assume that there is no other bean in the application.)" has been added to the problem statement.
Re: About Question enthuware.oce-ejbd.v6.2.429 :
Posted: Tue May 17, 2011 3:30 pm
by jszczepankiewicz
In the explanation there is:
"So remember that whenever the timer creation is to be done conditionally, it needs to be done programmatically."
The question is about automatic timer creation so I would change it to:
"So remember that whenever the timer creation has to be done unconditionally, it neds to be done automatically."
Re: About Question enthuware.oce-ejbd.v6.2.429 :
Posted: Thu May 19, 2011 11:37 am
by deadlock_gr
I don't have the question in front of me, but the opposite of programmatic creation is declarative creation. Not automatic.
Re: About Question enthuware.oce-ejbd.v6.2.429 :
Posted: Mon Feb 20, 2012 2:11 am
by Adamsus
On singletone bean you can create timer with garanted invocation on start.
Re: About Question enthuware.oce-ejbd.v6.2.429 :
Posted: Thu Oct 04, 2012 7:37 am
by fjwalraven
The answer to this question should be:
"This can be achieved using programmatic or automatic timer creation."
because the question doesn't state that the bean is not a Singleton. If it is a Singleton you can create a CalendarTimer on Startup like this (calling every second the timerSignal() method):
Code: Select all
@Singleton
@Startup
@LocalBean
public class SingleWithTimerCreation {
@Resource TimerService timer;
@PostConstruct
private void initTimer(){
ScheduleExpression se = new ScheduleExpression().hour("*").minute("*").second("*/1");
timer.createCalendarTimer(se);
}
@Timeout
public void timerSignal(){
System.out.println("Timer time-out");
}
}
Regards,
Frits
Re: About Question enthuware.oce-ejbd.v6.2.429 :
Posted: Fri Oct 05, 2012 5:12 pm
by admin
You are right. A statement has now been added to the question that makes it clear that it is not a singleton bean.
thank you for your feedback!