mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-161261 LowMemoryWatcher sporadically fails with ConcurrentModificationException
This commit is contained in:
@@ -21,8 +21,6 @@ import com.intellij.util.containers.WeakList;
|
||||
import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Eugene Zhuravlev
|
||||
* Date: Aug 24, 2010
|
||||
@@ -30,12 +28,12 @@ import java.util.List;
|
||||
public class LowMemoryWatcher {
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.util.LowMemoryWatcher");
|
||||
|
||||
private static final List<Runnable> ourListeners = new WeakList<Runnable>();
|
||||
private static final WeakList<Runnable> ourListeners = new WeakList<Runnable>();
|
||||
private final Runnable myRunnable;
|
||||
|
||||
static void onLowMemorySignalReceived() {
|
||||
LOG.info("Low memory signal received.");
|
||||
for (Runnable watcher : ourListeners) {
|
||||
for (Runnable watcher : ourListeners.toStrongList()) {
|
||||
try {
|
||||
watcher.run();
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@ import java.lang.management.MemoryPoolMXBean;
|
||||
import java.lang.management.MemoryType;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
public class LowMemoryWatcherManager implements Disposable {
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.util.LowMemoryWatcherManager");
|
||||
@@ -38,6 +39,7 @@ public class LowMemoryWatcherManager implements Disposable {
|
||||
private static final long MEM_THRESHOLD = 5 /*MB*/ * 1024 * 1024;
|
||||
|
||||
private Future<?> mySubmitted; // guarded by ourJanitor
|
||||
private final AtomicBoolean myProcessing = new AtomicBoolean();
|
||||
private final Runnable myJanitor = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
@@ -75,7 +77,7 @@ public class LowMemoryWatcherManager implements Disposable {
|
||||
if (MemoryNotificationInfo.MEMORY_THRESHOLD_EXCEEDED.equals(notification.getType()) ||
|
||||
MemoryNotificationInfo.MEMORY_COLLECTION_THRESHOLD_EXCEEDED.equals(notification.getType())) {
|
||||
if (Registry.is("low.memory.watcher.sync", true)) {
|
||||
myJanitor.run();
|
||||
handleEventImmediately();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -87,6 +89,18 @@ public class LowMemoryWatcherManager implements Disposable {
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private void handleEventImmediately() {
|
||||
if (myProcessing.compareAndSet(false, true)) {
|
||||
try {
|
||||
myJanitor.run();
|
||||
}
|
||||
finally {
|
||||
myProcessing.set(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private final NotNullLazyValue<ExecutorService> myExecutor = new NotNullLazyValue<ExecutorService>() {
|
||||
@NotNull
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user