Package COM.IBM.DG;
public class Main {public static void main (string[] args) {//TODO auto-generated method stub
Singletonclass s1 =singletonclass.getinstall ();
Singletonclass s2 = Singletonclass.getinstall (); System.out.println (S1==S2); True System.out.println (s1.equals (S2));
True}}//single case mode scenario and Opportunity:///////////////////////////////
The resource pool creates the connection, the database connects, but the general database all uses the connection pool, the single example pattern can cause waits package com.ibm.dg; public class Singletonclass {private Singletonclass () {}//define private constructor method private static Singletonclass Install=nul
L public static Singletonclass Getinstall () {if (install = null) {synchronized (Singletonclass.class) {// Synchronized when two concurrent threads access the synchronized (this) synchronized code block in the same object,//Only one time Threads are executed.
Another thread must wait until the current thread finishes executing the code block before executing the code block.
if (install = = NULL) {install = new Singletonclass ();
} } return install;
}
}