Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EJB-3.1 @Startup & @Schedule anotation in Apache Tomee for Timer Execution

I have following code to run on Apache-tomee, i am using eclipse for coding, and i want to run my simple schedule job using @Schedule annotation at application start-up.

@Startup
@Singleton
public class ScheduleEJB {
    private static int count = 0;
    @Schedule(second="*/10", minute="*", hour="*", info="MyTimer")
    public void execute() {
       System.out.println("its running count..."+count);
       count++;
    }
}

When i deployed this code on Tomee, it get me following message and unable to run my schedule method execute() automatically at startup, where as this code works fine in glassfish, but i am not going to use it either glassfish of jboss.

Dec 21, 2012 9:59:45 AM org.quartz.impl.StdSchedulerFactory instantiate
INFO: Using default implementation for ThreadExecutor
Dec 21, 2012 9:59:45 AM org.quartz.core.SchedulerSignalerImpl
INFO: Initialized Scheduler Signaller of type: class org.quartz.core.SchedulerSignalerImpl
Dec 21, 2012 9:59:45 AM org.quartz.core.QuartzScheduler
INFO: Quartz Scheduler v.2.1.6 created.
Dec 21, 2012 9:59:45 AM org.quartz.simpl.RAMJobStore initialize
INFO: RAMJobStore initialized.
Dec 21, 2012 9:59:45 AM org.quartz.core.QuartzScheduler initialize
INFO: Scheduler meta-data: Quartz Scheduler (v2.1.6) 'OpenEJB-TimerService-Scheduler' with instanceId 'OpenEJB'
Scheduler class: 'org.quartz.core.QuartzScheduler' - running locally.
NOT STARTED.
Currently in standby mode.
Number of jobs executed: 0
Using thread pool 'org.apache.openejb.core.timer.DefaultTimerThreadPoolAdapter' - with 0 threads.
Using job-store 'org.quartz.simpl.RAMJobStore' - which does not support persistence. and is not clustered.

Dec 21, 2012 9:59:45 AM org.quartz.impl.StdSchedulerFactory instantiate
INFO: Quartz scheduler 'OpenEJB-TimerService-Scheduler' initialized from an externally provided properties instance.
Dec 21, 2012 9:59:45 AM org.quartz.impl.StdSchedulerFactory instantiate
INFO: Quartz scheduler version: 2.1.6
Dec 21, 2012 9:59:45 AM org.quartz.core.QuartzScheduler start
INFO: Scheduler OpenEJB-TimerService-Scheduler_$_OpenEJB started.
Dec 21, 2012 9:59:45 AM org.apache.openejb.assembler.classic.Assembler createApplication
INFO: Created Ejb(deployment-id=ScheduleEJB, ejb-name=ScheduleEJB, container=My Singleton Container)
Dec 21, 2012 9:59:45 AM org.apache.openejb.assembler.classic.Assembler createApplication
INFO: Started Ejb(deployment-id=ScheduleEJB, ejb-name=ScheduleEJB, container=My Singleton Container)

like image 271
rykhan Avatar asked Dec 21 '12 05:12

rykhan


People also ask

What's new in EJB 3 1?

The EJB 3.1 specification addresses this problem by removing the restriction that enterprise bean classes must be packaged in an ejb-jar file. You now have the option of placing EJB classes directly in the .war file, using the same packaging guidelines that apply to web application classes.

Can I add a startup bean to an EJB project?

You can, however, include one EJB 2.1 project in an EAR 5.0 project, and add a Startup Bean in this EJB 2.1 project, which will execute at Application Startup. Snippet from ejb-jar.xml

What is the default attribute for initializing EJB type?

Attribute default: FALSE (initialize EJB type when EJB is first used by application) for beans other than message-driven beans. Always TRUE for message-driven beans.

How do I initialize EJBs at application start time?

You can configure EJBs so that they are initialized at application start time by changing a setting in the Administrative Console (see Related URL: Changing enterprise bean types to initialize at application start time using the administrative console).


1 Answers

Did you already have a look to TomEE examples page? There is a similar example which actually running.

http://openejb.apache.org/examples-trunk/schedule-methods/README.html

Maybe you could give it a try and check what is actually different with yours.

like image 97
jlmonteiro Avatar answered Sep 22 '22 19:09

jlmonteiro