This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.concurrent.locks.ReentrantLock; | |
| public class Singleton { | |
| private ReentrantLock lock = new ReentrantLock(); | |
| private Singleton instance = null; | |
| public Singleton getInstance() { | |
| // this creates an auxiliary variable to prevent another thread wait the synchronized block gets unlock | |
| Singleton result = instance; | |