From 7ac81ee11fcc4569dd73cfef27cbef668900b159 Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Wed, 15 Mar 2017 13:06:50 +0300 Subject: [PATCH] use other thread instead of EDT as an argument to notifyThreadBusy to avoid tests crash --- .../intellij/openapi/application/impl/ApplicationImpl.java | 6 +++++- .../src/com/intellij/util/concurrency/AppDelayQueue.java | 4 ++++ .../util/concurrency/AppScheduledExecutorService.java | 4 ++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/platform/platform-impl/src/com/intellij/openapi/application/impl/ApplicationImpl.java b/platform/platform-impl/src/com/intellij/openapi/application/impl/ApplicationImpl.java index 5a7343917765..ea0afa4dd67d 100644 --- a/platform/platform-impl/src/com/intellij/openapi/application/impl/ApplicationImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/application/impl/ApplicationImpl.java @@ -221,7 +221,11 @@ public class ApplicationImpl extends PlatformComponentManagerImpl implements App gatherStatistics = LOG.isDebugEnabled() || isUnitTestMode() || isInternal(); Thread edt = UIUtil.invokeAndWaitIfNeeded(() -> { - AWTAutoShutdown.getInstance().notifyThreadBusy(Thread.currentThread()); // needed for EDT not to exit suddenly + // instantiate AppDelayQueue which starts "Periodic task thread" which we'll mark busy to prevent this EDT to die + // that thread was chosen because we know for sure it's running + AppScheduledExecutorService service = (AppScheduledExecutorService)AppExecutorUtil.getAppScheduledExecutorService(); + Thread thread = service.getPeriodicTasksThread(); + AWTAutoShutdown.getInstance().notifyThreadBusy(thread); // needed for EDT not to exit suddenly return Thread.currentThread(); }); myLock = new ReadMostlyRWLock(edt); diff --git a/platform/util/src/com/intellij/util/concurrency/AppDelayQueue.java b/platform/util/src/com/intellij/util/concurrency/AppDelayQueue.java index 543ebbb13765..f73afdbec8c8 100644 --- a/platform/util/src/com/intellij/util/concurrency/AppDelayQueue.java +++ b/platform/util/src/com/intellij/util/concurrency/AppDelayQueue.java @@ -84,4 +84,8 @@ class AppDelayQueue extends DelayQueue throw new RuntimeException(e); } } + + Thread getThread() { + return scheduledToPooledTransferer; + } } diff --git a/platform/util/src/com/intellij/util/concurrency/AppScheduledExecutorService.java b/platform/util/src/com/intellij/util/concurrency/AppScheduledExecutorService.java index c115c64f9919..c9b5802ae2a4 100644 --- a/platform/util/src/com/intellij/util/concurrency/AppScheduledExecutorService.java +++ b/platform/util/src/com/intellij/util/concurrency/AppScheduledExecutorService.java @@ -208,4 +208,8 @@ public class AppScheduledExecutorService extends SchedulingWrapper { error(); } } + @NotNull + public Thread getPeriodicTasksThread() { + return delayQueue.getThread(); + } }