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

2

6

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)

Fy answered 21/12, 2012 at 5:36 Comment(0)
C
1

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.

Concentration answered 21/12, 2012 at 8:7 Comment(1)
yes, i have checked its the same thing, but my problem was not how to code it, was how i will be able to run that code in tomee, and interestingly what i found the solution, that if i run my project by deploying directly from eclipse on a running tomee server, it will not start the timer, but when i just deployed the app and restart the server it just start my timer, so i am unable to figure out the reason.Fy
D
0

Your code runs fine on last release of TomEE. What was your version?

Dorella answered 22/12, 2012 at 18:32 Comment(1)
it was apache-tomee-1.5.1-plus, yes it runs and working fine now, but for which i have to restart tomee after deploying my code... the reason i am unable to figure outFy

© 2022 - 2024 — McMap. All rights reserved.