@@ -68,14 +68,14 @@ public class ToMany<TARGET> implements List<TARGET>, Serializable {
68
68
private final Object entity ;
69
69
private final RelationInfo <Object , TARGET > relationInfo ;
70
70
71
- private ListFactory listFactory ;
71
+ private volatile ListFactory listFactory ;
72
72
private List <TARGET > entities ;
73
73
74
74
/** Counts of all entities in the list ({@link #entities}). */
75
75
private Map <TARGET , Integer > entityCounts ;
76
76
77
77
/** Entities added since last put/sync. Map is used as a set (value is always Boolean.TRUE). */
78
- private Map <TARGET , Boolean > entitiesAdded ;
78
+ private volatile Map <TARGET , Boolean > entitiesAdded ;
79
79
80
80
/** Entities removed since last put/sync. Map is used as a set (value is always Boolean.TRUE). */
81
81
private Map <TARGET , Boolean > entitiesRemoved ;
@@ -129,14 +129,16 @@ public synchronized void setRemoveFromTargetBox(boolean removeFromTargetBox) {
129
129
}
130
130
131
131
public ListFactory getListFactory () {
132
- if (listFactory == null ) {
132
+ ListFactory result = listFactory ;
133
+ if (result == null ) {
133
134
synchronized (this ) {
134
- if (listFactory == null ) {
135
- listFactory = new CopyOnWriteArrayListFactory ();
135
+ result = listFactory ;
136
+ if (result == null ) {
137
+ listFactory = result = new CopyOnWriteArrayListFactory ();
136
138
}
137
139
}
138
140
}
139
- return listFactory ;
141
+ return result ;
140
142
}
141
143
142
144
private void ensureBoxes () {
0 commit comments