Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

java singleton with synchronized

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 :: how to make more than one jlabel at once in java 
Java :: which exception is thrown when java is out of memory 
Java :: set length java 
Java :: what is datasnapshot.getkey() in android studio 
Java :: split the argument String and add the tokens into a list 
Java :: diamonds 
Java :: getBatteryPercentage android studio 
Java :: lcm 
Java :: resources/android/xml/network_security_config.xml 
Java :: string.equals 
Java :: java.lang.IllegalStateException: Not scheduled yet 
Java :: has 8 digit in number 
Java :: JDA send DM 
Java :: factorial java recursion 
Java :: java run multiple cmd commands 
Java :: how to start java project in intellij 
Java :: Write a java program to print a number from the user 
Java :: java switch expression produce result 
Java :: java jbutton hover 
Java :: substring in java 
Java :: Write a java program to print the ip address 
Java :: wrap text in jscrollpane 
Java :: Volkswagen fox 
Java :: android java how to clear or close cursor 
Java :: sartt timer of 40 second when send otp andrpid 
Java :: java-util of geofence polygon 
Java :: how to convert string to space separated int in java 
Java :: java combine to byte[] 
Java :: Meeting time: Merging Ranges (return) 
Java :: classloader in static method 
ADD CONTENT
Topic
Content
Source link
Name
7+4 =