About Question enthuware.oce-ejbd.v6.2.429 :
Moderators: Site Manager, fjwalraven
About Question enthuware.oce-ejbd.v6.2.429 :
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?
Is it not so?
-
- Site Admin
- Posts: 10388
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.oce-ejbd.v6.2.429 :
I am not sure if you can create a timer for another bean.
Re: About Question enthuware.oce-ejbd.v6.2.429 :
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.
-
- Site Admin
- Posts: 10388
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.oce-ejbd.v6.2.429 :
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 :
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."
"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."
-
- Posts: 54
- Joined: Tue Apr 19, 2011 10:32 am
- Contact:
Re: About Question enthuware.oce-ejbd.v6.2.429 :
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 :
On singletone bean you can create timer with garanted invocation on start.
-
- Posts: 429
- Joined: Tue Jul 24, 2012 2:43 am
- Contact:
Re: About Question enthuware.oce-ejbd.v6.2.429 :
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):
Regards,
Frits
"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");
}
}
Frits
-
- Site Admin
- Posts: 10388
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.oce-ejbd.v6.2.429 :
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!
thank you for your feedback!
Who is online
Users browsing this forum: Bing [Bot] and 11 guests