Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Singleton {
- private class A {
- final int value;
- }
- private static A state = null;
- private static boolean exists = true;
- private Mutex mutex;
- Signleton() {}
- public A getState() {
- if (exists) {
- return state;
- }
- mutex.lock();
- try {
- if (state == null) {
- state = new A();
- if (state != null) {
- exists = true;
- }
- }
- } finally {
- mutex.unlock();
- }
- return state;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement