Synchronise the list as multiple threads are calling it
This commit is contained in:
parent
5d970438bf
commit
7ab799c452
@ -3,6 +3,7 @@ package com.iluwatar.singleton;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.*;
|
import java.util.concurrent.*;
|
||||||
|
|
||||||
@ -18,7 +19,7 @@ import static org.junit.Assert.assertEquals;
|
|||||||
public class LazyLoadedSingletonThreadSafetyTest {
|
public class LazyLoadedSingletonThreadSafetyTest {
|
||||||
|
|
||||||
private static final int NUM_THREADS = 5;
|
private static final int NUM_THREADS = 5;
|
||||||
private List<ThreadSafeLazyLoadedIvoryTower> threadObjects = new ArrayList<>();
|
private List<ThreadSafeLazyLoadedIvoryTower> threadObjects = Collections.synchronizedList(new ArrayList<>());
|
||||||
|
|
||||||
//NullObject class so Callable has to return something
|
//NullObject class so Callable has to return something
|
||||||
private class NullObject{private NullObject(){}}
|
private class NullObject{private NullObject(){}}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user