EJB's Timer

Source: Internet
Author: User
Tags call back jboss

EJB Timer

    • Either: Annotation @Schedule or method before declaring @timeout
    • Either: Define Timeout-method in the deployment description

    • If you are using @schedule, the timer can support multiple in one EJB, such as:


@Schedule (second= "*/2", minute= "*", hour= "*", persistent=false,info= "Timer1")
public void DoWork () {
System.out.println ("Hi from the EJB timer example!");
}


@Schedule (second= "*/1", minute= "*", hour= "*", persistent=false,info= "Timer2")
public void DoWork2 () {
System.out.println ("Hi ....") 2nd timer! ");
}
Each of the above starts with 2 timer, one executes every 2 seconds, and one executes every 1 seconds. Container does concurrent access control at execution time. That means the callback method can only execute one method at a time.

    • If you are using @timeout, which is programmatic timers, the callback method has only one.

All timers created via one of the Timerservice timer creation methods for a particular component use a single timeout call Back method. --from EJB Spec 3.1 Chapter 18
If the previous call is not completed and the next timer comes up, then the timer will wait (that is, lock). As follows:

09:20:59,045 ERROR [org.jboss.as.ejb3] (EJB default-2) jbas014122:error during retrying timeout for timer: [id=c2a31520 -2c55-4b01-b362-d8dfdb73a2d0 Timedobjectid=jboss-ejb-timer.jboss-ejb-timer.timeoutexample Auto-timer?:false persistent?:false [email protected]86ae8 initialexpiration=tue Mar 09:20:48 CST intervalduration (in milli sec) =0 N Extexpiration=null TIMERSTATE=RETRY_TIMEOUT:JAVAX.EJB.CONCURRENTACCESSTIMEOUTEXCEPTION:JBAS014373:EJB 3.1 PFD2 4.8.5.5.1 concurrent access timeout on [email protected]-could not obtain lock within 5000MILLISECONDS
At Org.jboss.as.ejb3.concurrency.ContainerManagedConcurrencyInterceptor.processInvocation ( CONTAINERMANAGEDCONCURRENCYINTERCEPTOR.JAVA:100) [jboss-as-ejb3-7.3.0.final-redhat-14.jar:7.3.0.final-redhat-14 ]

After the timer waits 5 seconds, it will retry again (JBoss implementation). If it is a timeout, it will be discarded.

Timerservice's Createsingleactiontimer () and Createintervaltimer ()

    • Createsingleactiontimer

Trigger only once, if the trigger is not the lock, timeout, as described above, try again, if not, give up directly.

    • Createintervaltimer

Periodic trigger, point trigger found the last not finished, then skip directly, give up, and then wait for the next, the following code

@Timeout
public void Scheduler (timer timer) {
System.out.println ("EJB timer:info=" + timer.getinfo () + "" + Thread.CurrentThread (). GetName ());

Added by Xilun
try {
Thread.Sleep (1000*30);
} catch (Interruptedexception e) {
E.printstacktrace ();
}
}


//
@PostConstruct
public void Initialize (Invocationcontext ctx) {
//...
Timerservice.createintervaltimer (10*1000, New Timerconfig ("Single Timer #2", false));
//....
}

The output log is as follows:
10:21:47,864 INFO [stdout] (EJB default-7) EJB timer:info=single Timer #2 EJB default-7

10:21:57,864 WARN [org.jboss.as.ejb3] (EJB default-9) jbas014143:a Previous execution of timer [jboss-ejb-timer.jboss- Ejb-timer. Timeoutexample 8ba38f5a-0da7-4993-8b0b-e69854f61ee4] is still in progress, skipping this overlapping scheduled execution At:tue Mar 10:21:57 CST 2016
10:22:07,864 WARN [org.jboss.as.ejb3] (EJB default-6) jbas014143:a Previous execution of timer [jboss-ejb-timer.jboss- Ejb-timer. Timeoutexample 8ba38f5a-0da7-4993-8b0b-e69854f61ee4] is still in progress, skipping this overlapping scheduled execution At:tue Mar 10:22:07 CST 2016
10:22:17,864 WARN [org.jboss.as.ejb3] (EJB default-8) jbas014143:a Previous execution of timer [jboss-ejb-timer.jboss- Ejb-timer. Timeoutexample 8ba38f5a-0da7-4993-8b0b-e69854f61ee4] is still in progress, skipping this overlapping scheduled execution At:tue Mar 10:22:17 CST 2016
10:22:27,865 INFO [stdout] (EJB default-3) EJB timer:info=single Timer #2 EJB default-3

10:22:37,864 WARN [org.jboss.as.ejb3] (EJB default-10) jbas014143:a Previous execution of timer [Jboss-ejb-timer.jboss -ejb-timer. Timeoutexample 8ba38f5a-0da7-4993-8b0b-e69854f61ee4] is still in progress, skipping this overlapping scheduled execution At:tue Mar 10:22:37 CST 2016
10:22:47,864 WARN [org.jboss.as.ejb3] (EJB default-2) jbas014143:a Previous execution of timer [jboss-ejb-timer.jboss- Ejb-timer. Timeoutexample 8ba38f5a-0da7-4993-8b0b-e69854f61ee4] is still in progress, skipping this overlapping scheduled execution At:tue Mar 10:22:47 CST 2016
10:22:57,864 WARN [org.jboss.as.ejb3] (EJB default-1) jbas014143:a Previous execution of timer [jboss-ejb-timer.jboss- Ejb-timer. Timeoutexample 8ba38f5a-0da7-4993-8b0b-e69854f61ee4] is still in progress, skipping this overlapping scheduled execution At:tue Mar 10:22:57 CST 2016

There is an example of a timer in Jboss QuickStart.


EJB's Timer

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.