fix viewable thread-safety
This commit is contained in:
parent
ffe3d3dc35
commit
affa0f4c84
1 changed files with 7 additions and 5 deletions
|
@ -11,14 +11,16 @@ import java.util.concurrent.ConcurrentLinkedQueue;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public abstract class Viewable {
|
public abstract class Viewable {
|
||||||
private final static List<WeakReference<Viewable>> all = new ArrayList<>();
|
private final static List<WeakReference<Viewable>> all = Collections.synchronizedList(new ArrayList<>());
|
||||||
|
|
||||||
public static List<Viewable> all() {
|
public static List<Viewable> all() {
|
||||||
|
synchronized (all) {
|
||||||
all.removeIf(reference -> reference.get() == null);
|
all.removeIf(reference -> reference.get() == null);
|
||||||
return all.stream()
|
return all.stream()
|
||||||
.map(Reference::get)
|
.map(Reference::get)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private boolean queueRunning = false;
|
private boolean queueRunning = false;
|
||||||
private final Queue<Runnable> visibilityTaskQueue = new ConcurrentLinkedQueue<>();
|
private final Queue<Runnable> visibilityTaskQueue = new ConcurrentLinkedQueue<>();
|
||||||
|
|
Loading…
Reference in a new issue