• Jmesa is a dynamic HTML table that allows you to filter, sort, paginate, export and edit your data however you need to
< h2 > < a href="showalladv.action" > Jmesa Advanced Report< / a > < / h2 >
2.web.xml: < ? xml version="1.0" encoding="UTF-8"? > < web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0" > < display-name > Report < / display-name > < filter > < filter-name > f1 < / filter-name > < filter-class > org.apache.struts2.dispatcher.FilterDispatcher < / filter-class > < / filter > < filter-mapping > < filter-name > f1 < / filter-name > < url-pattern > /* < / url-pattern > < / filter-mapping > < / web-app > In given Program all the specified requirement for singleton pattern is satisfied i.e
Step 2: Made default constructor private
Step 3: Create a Method for getting the reference to the Singleton Object and make it as synchronised
• We write a public static getter or access method to get the instance of the Singleton Object at runtime. First time the object is created inside this method as it is null. Subsequent calls to this method returns the same object created as the object is globally declared (private) and the hence the same referenced object is returned.
• It could happen that the access method may be called twice from 2 different classes at the same time and hence more than one object being created. This could violate the design patter principle. In order to prevent the simultaneous invocation of the getter method by 2 threads or classes simultaneously we add the synchronized keyword to the method declaration.
Step 4: Override the Object clone method to prevent cloning.
We can still be able to create a copy of the Object by cloning it using the Object’s clone method. This can be done as shown below
SingletonObjectDemo clonedObject = (SingletonObjectDemo) obj.clone();
This again violates the Singleton Design Pattern’s objective. So to deal with this we need to override the Object’s clone method which throws a CloneNotSupportedException exception.
Step 5: Create class SingletonObjectDemo to test the Singleton pattern
Run the given class as java Application and we will get the output