WebLogic SingletonService for High Availability Scenarios: Create Logic that Runs Only in One Node of a Cluster at a Time and Fails Over Other Cluster Node when Things go Wrong or Maintenance is Needed

I recently visited a Package Delivery Company Customer (SxxR) who needed to implement a logic consisting in a background thread scanning continuously a shared directory containing acknowledgement of receipts of shipments files that must be processed and then passed to another stage.

How can we make this logic HA?

The answer is SingletonService: runs only in one of the managed servers of a cluster but it is migrated automatically if the server fails or is stopped.


Create a java Class like this:

package miapp;

 import weblogic.cluster.singleton.SingletonService;

 public class MyUniqueWorker implements SingletonService{

 public void activate() {

                    System.out.println(“***************** activate called *************”);


 public void deactivate() {

                    System.out.println(“***************** de-activate called *************”);



Put the Class in a jar file, singleton.jar for instance

Put the following in weblogic-application.xml:



     <name>mySingleTown ;-)</name>



Package the jar in an ear app:


Deploy the ear to the cluster.

Create the managed servers, machine and cluster and configure it as follows:

singleton1 singleton2 singleton3 singleton4 singleton5


The logic runs in one mnaged server, but if the server where it is running fails or is stopped the  execution jupms to other managed server in the cluster.

####<Jun 24, 2015 1:04:20 AM CEST> <Notice> <Stdout> <JMUGUETA-ES> <server1> <[STANDBY] ExecuteThread: ‘2’ for queue: ‘weblogic.kernel.Default (self-tuning)’> <<WLS Kernel>> <> <> <1435100660323> <BEA-000000> <***************** de-activate called *************>

####<Jun 24, 2015 1:04:28 AM CEST> <Notice> <Stdout> <JMUGUETA-ES> <server2> <[STANDBY] ExecuteThread: ‘4’ for queue: ‘weblogic.kernel.Default (self-tuning)’> <<WLS Kernel>> <> <> <1435100668652> <BEA-000000> <***************** activate called *************>

####<Jun 24, 2015 1:04:28 AM CEST> <Info> <Cluster> <JMUGUETA-ES> <server2> <[STANDBY] ExecuteThread: ‘4’ for queue: ‘weblogic.kernel.Default (self-tuning)’> <<WLS Kernel>> <> <> <1435100668653> <BEA-000189> <The Singleton Service mySingleTown 😉 is now active on this server.>

Enjoy 😉

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.