Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

java singleton with synchronized double check

private static final Object lock = new Object();
private static volatile YourObject instance;

public static YourObject getInstance() {
    YourObject r = instance;
    if (r == null) {
        synchronized (lock) {    // While we were waiting for the lock, another 
            r = instance;        // thread may have instantiated the object.
            if (r == null) {  
                r = new YourObject();
                instance = r;
            }
        }
    }
    return r;
}
Comment

PREVIOUS NEXT
Code Example
Java :: regex pattern for car plates 
Java :: last element array java 
Java :: print current user roles in java 
Java :: RTC_WAKEUP 
Java :: store files system in tree java 
Java :: how to create space between element in vbox in javafx 
Java :: codegrepper java instanceof 
Java :: click selectable in androiod 
Java :: castle stones java qn 
Java :: java.lang.number is interface or abstract class 
Java :: JAVA for-each Loop Sytnax 
Java :: integer to roman 
Java :: Java Creating ArrayDeque 
Java :: Uri/Beecrowd problem no - 1146 solution in Java 
Java :: java radom float 
Java :: java producer consumer queue 
Java :: java 8 if else in one statement 
Java :: java for loop example 
Java :: java remove element from list 
Java :: android studio doesnt work when in full screen mac os 
Java :: Java 17 not showing in linux 
Java :: Automatic Code Completion in NetBeans 
Java :: multipleQuastion.Java 
Java :: darkhub 
Java :: java add backslash into string 
Java :: how to get data from firebase notification in java 
Java :: what is minecraft default render distance 
Java :: {1 2 3 4 5 } 
Java :: if(ResultSet.next()) 
Java :: Description Resource Path Location Type ApplicationContext cannot be resolved to a type Mobile.java /InversionOfControl/src/com/deloitte/springioc line 13 Java Problem 
ADD CONTENT
Topic
Content
Source link
Name
5+7 =