1 package cz.cuni.amis.utils;
2
3
4
5
6
7
8
9
10
11
12 public abstract class SyncLazy<T> extends Lazy<T> {
13
14 private Object mutex = new Object();
15
16
17
18
19
20 @Override
21 public T getVal() {
22 return get();
23 }
24
25
26
27
28 @Override
29 public T get() {
30 if (obj != null) {
31 return obj;
32 }
33 synchronized(mutex) {
34 if (obj != null) return obj;
35 obj = create();
36 return obj;
37 }
38 }
39
40 @Override
41 public void set(T val) {
42 synchronized(mutex) {
43 this.obj = val;
44 }
45 }
46
47 }