Showing posts with label timer. Show all posts
Showing posts with label timer. Show all posts

Saturday, July 23, 2016

EJB Timer stops working in WLS 12.1.3 after an exception occurs

On Version: WebLogic Server 12.1.3.0.0, Java 1.7.0_51

package com.pierre.timertest;

import javax.ejb.Schedule;
import javax.ejb.Stateless;
import javax.ejb.Timer;

@Stateless
public class TimerTestEJB {
 public static int count = 0;

    /**
     * Default constructor. 
     */
    public TimerTestEJB() {
        // TODO Auto-generated constructor stub
    }
 
 @SuppressWarnings("unused")
 @Schedule(second="*/10", minute="*", hour="*", dayOfWeek="*",
      dayOfMonth="*", month="*", year="*", info="MyTimer")
    private void scheduledTimeout(final Timer t) {
  count++;
        System.out.println("@Schedule called at: " + new java.util.Date() + " count=" + count);
        if (count == 5) {
         System.out.println("@Schedule count = 5, throwing Exception");
         throw new Error("@Schedule count = 5");
        }
    }
}



This funnily will still work for count=6, then stop.

Luckily the bug has been fixed (god bless oracle engineers), see

Oracle WebLogic Server Patch Set Update 12.1.3.0.160719 Fixed Bugs List (Doc ID 2162294.1)

19689036 12.1.3.0.160719 Timer EJB will stop when timer expiration is success and previous timer expiration is failed.

Patch 19689036: NON-PERSISTENT CALENDAR-BASED TIMER IS CANCELED IF CALLBACK METHOD THROWS SYSTEM

In reality even PERSISTENT timers fail...in fact by default @Schedule creates a persistent timer, and also adding persistent=true doesn't fix the issue.
I download p19689036_121300_Generic.zip, extract the weblogic\ejb\container\timer\TimerImpl.class, put in a JAR that I prepend to the WLS classpath, and now the timer keeps working even after the Error occurs.... awesome ! (PS I am too lazy to properly apply the patch with opatch...)


Here http://docs.oracle.com/cd/E14571_01/web.1111/e13719/implementing.htm#EJBPG213 they mention: weblogic.ejb.WLTimerInfo (there is a maxRetryAttempts) and "Configuring Automatic Retry of Container-Managed Transactions" ... this could keep you going even without applying the patch...



Sunday, May 8, 2016

Singleton Timer in WebLogic

If you have a JEE EJB Timer in a Cluster, maybe you want only 1 instance to be active. In this case you should implement a Cluster Aware Singleton Component :
https://blogs.oracle.com/muraliveligeti/entry/ejb_timer_ejb

- create table WEBLOGIC_TIMERS

configure a Datasource and set it in "cluster-Scheduling":






Friday, May 4, 2012

ClusterTimer, Updated time skew

I have seen in the logs this Info:

ClusterTimer, Updated time skew. New skew is -3 Old skew was 3 and Urzeit is 1334181600000




Since I am as curious as a cat, I have searched and found out that this is logged by com.bea.wli.timer.TimeSkewSynchronizer,

running a TimeSkewSynchronizerTask which in turn uses a ClusterTimerService which uses a ClusterTimerPersistenceStore to persist the Urzeit (apart from being a mythological archetype, it's also a universal time reference).

more to come...

Thursday, December 16, 2010

CommonJ timer with OSB, SOA Suite, SOA Scheduler

an excellent document on SOA Scheduler here:

http://www.oracle.com/technetwork/middleware/soasuite/learnmore/soascheduler-186798.pdf


I have tested it and it works beautifully! You can specify the cron parameters in a single place. Of course it can be improved but it's a good starting point.
Here the code (I hope Robert Baumgartner doesn't mind).
I feel it would be better to have the Scheduler post an EDN event using
oracle.integration.platform.blocks.event.SendEvent and wake up a Mediator instance,
rather than synchronously invoke the WS to trigger the BPEL process.

This SendEvent class is in C:\Oracle1\Middleware\jdeveloper\soa\modules\oracle.soa.fabric_11.1.1\fabric-runtime.jar
Unfortunately it looks like the only way to use it is by invoking its main(...) procedure after having set the System properties with: dbconn,dbuser, dbpass, eventName, eventBody,event parameters. Internally it uses a SAQRemoteBusinessEventConnectionFactory and a BusinessEventBuilder. All this make it a bit complicated to generate events programmatically.


here is CommonJ doc:

http://download.oracle.com/docs/cd/E12840_01/wls/docs103/commonj/commonj.html with coverage of "cluster-wide" timers.


Here the excellent tutorial by James Bayer:
http://blogs.oracle.com/jamesbayer/2007/11/weblogic_scheduling_a_polling.html

and more here:
http://blogs.oracle.com/jamesbayer/2009/04/a_simple_job_scheduler_example.html


and a very nice tutorial on CommonJ TimerManager here
http://middlewaremagic.com/weblogic/?p=987

here the code


Other alternatives:

EJB 3.0 Timer:
http://www.javabeat.net/articles/3-ejb-30-timer-services-an-overview-1.html

more specifically in a cluster:
http://shaoxiongyang.blogspot.com/2010/10/how-to-use-ejb-3-timer-in-weblogic-10.html


I really feel a pain comparing the SOA Suite support for scheduling with the one offered by Apache Camel:
http://camel.apache.org/quartz.html



(17-Jan-2011) I discover there is a PICK activity in BPEL allowing you to schedule a BPEL process at given interval. This is most likely the simplest solution:

http://download.oracle.com/docs/cd/B31017_01/integrate.1013/b28981/events.htm#CHDECBGD