Singleton Service Pattern
Learn the Singleton Service design pattern and its usage.
We'll cover the following...
Intent
This pattern is to ensure that only a single instance of a service can be active at a time.The Singleton Service pattern is also known as the HA Singleton in the clustered JBoss EAP.
Context and problem
We have seen how the Service Instance pattern can help us improve a service’s performance and availability. The system has increased throughput and availability by running multiple instances of the same service and having a request dispatcher capable of load balancing the requests to all available service instances. The system’s availability also increases because if an instance of the service becomes unavailable, the request dispatcher detects this and forwards future requests to running instances. There are certain use cases where only one instance of a service is allowed to run at a time. For example, if we have a scheduled job (a trigger-based service) and run multiple instances of the same job, every instance would trigger at the scheduled intervals rather than having only one trigger fired as expected by the business.
Another example would be if the service performs polling on certain resources (a file system or database), and we want to ensure that only a single instance, and maybe even a single thread performs the polling and processing. In all these plus similar ...