About Question enthuware.oce-ejbd.v6.2.429 :

All the posts and topics that contain only an error report will be moved here after the error is corrected. This is to ensure that when users view a question in ETS Viewer, the "Discuss" button will not indicate the presence of a discussion that adds no value to the question.

Moderators: Site Manager, fjwalraven

Post Reply
ETS User

About Question enthuware.oce-ejbd.v6.2.429 :

Post 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?

Online
admin
Site Admin
Posts: 10388
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.oce-ejbd.v6.2.429 :

Post by admin »

I am not sure if you can create a timer for another bean.

Guest

Re: About Question enthuware.oce-ejbd.v6.2.429 :

Post 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.

Online
admin
Site Admin
Posts: 10388
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.oce-ejbd.v6.2.429 :

Post by admin »

A statement "(Assume that there is no other bean in the application.)" has been added to the problem statement.

jszczepankiewicz

Re: About Question enthuware.oce-ejbd.v6.2.429 :

Post 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."

deadlock_gr
Posts: 54
Joined: Tue Apr 19, 2011 10:32 am
Contact:

Re: About Question enthuware.oce-ejbd.v6.2.429 :

Post by deadlock_gr »

I don't have the question in front of me, but the opposite of programmatic creation is declarative creation. Not automatic.

Adamsus

Re: About Question enthuware.oce-ejbd.v6.2.429 :

Post by Adamsus »

On singletone bean you can create timer with garanted invocation on start.

fjwalraven
Posts: 429
Joined: Tue Jul 24, 2012 2:43 am
Contact:

Re: About Question enthuware.oce-ejbd.v6.2.429 :

Post 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

Online
admin
Site Admin
Posts: 10388
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.oce-ejbd.v6.2.429 :

Post 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!

Post Reply

Who is online

Users browsing this forum: No registered users and 14 guests