From da6f32743faccda8e8431e712c2e63729cd2389f Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Tue, 3 Dec 2019 14:49:12 +0100 Subject: [PATCH] cleanup GitOrigin-RevId: 4c43f584bc04bce63ca28bc55a91e1891e21b546 --- .../application/impl/ApplicationImpl.java | 3 ++- .../util/concurrency/AppDelayQueue.java | 20 +++----------- .../AppScheduledExecutorService.java | 2 +- .../util/concurrency/SchedulingWrapper.java | 26 +++++++++++-------- 4 files changed, 21 insertions(+), 30 deletions(-) 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 b89fab6657d3..2b38a21fd6be 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 @@ -337,7 +337,7 @@ public class ApplicationImpl extends PlatformComponentManagerImpl implements App service.shutdownAppScheduledExecutorService(); super.dispose(); - Disposer.dispose(myLastDisposable); // dispose it last + Disposer.dispose(myLastDisposable); if (gatherStatistics) { //noinspection TestOnlyProblems @@ -1130,6 +1130,7 @@ public class ApplicationImpl extends PlatformComponentManagerImpl implements App } } + @Nullable private String id() { Class aClass = getClass(); String name = aClass.getName(); diff --git a/platform/util/src/com/intellij/util/concurrency/AppDelayQueue.java b/platform/util/src/com/intellij/util/concurrency/AppDelayQueue.java index 5b2b8fe234aa..0a73740ffa89 100644 --- a/platform/util/src/com/intellij/util/concurrency/AppDelayQueue.java +++ b/platform/util/src/com/intellij/util/concurrency/AppDelayQueue.java @@ -1,18 +1,4 @@ -/* - * Copyright 2000-2016 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.util.concurrency; import com.intellij.openapi.diagnostic.Logger; @@ -27,7 +13,7 @@ import java.util.concurrent.atomic.AtomicBoolean; * It starts the background thread which polls the queue for tasks ready to run and sends them to the appropriate executor. * The {@link #shutdown()} must be called before disposal. */ -class AppDelayQueue extends DelayQueue { +final class AppDelayQueue extends DelayQueue> { private static final Logger LOG = Logger.getInstance(AppDelayQueue.class); private final Thread scheduledToPooledTransferrer; private final AtomicBoolean shutdown = new AtomicBoolean(); @@ -37,7 +23,7 @@ class AppDelayQueue extends DelayQueue scheduledToPooledTransferrer = new Thread(() -> { while (!shutdown.get()) { try { - final SchedulingWrapper.MyScheduledFutureTask task = take(); + SchedulingWrapper.MyScheduledFutureTask task = take(); if (LOG.isTraceEnabled()) { LOG.trace("Took "+BoundedTaskExecutor.info(task)); } diff --git a/platform/util/src/com/intellij/util/concurrency/AppScheduledExecutorService.java b/platform/util/src/com/intellij/util/concurrency/AppScheduledExecutorService.java index 2a83243cda04..a1c54253de83 100644 --- a/platform/util/src/com/intellij/util/concurrency/AppScheduledExecutorService.java +++ b/platform/util/src/com/intellij/util/concurrency/AppScheduledExecutorService.java @@ -209,7 +209,7 @@ public final class AppScheduledExecutorService extends SchedulingWrapper { mainLock.lock(); Set workers; try { - HashSet workersField = ReflectionUtil.getField(executor.getClass(), executor, HashSet.class, "workers"); + Set workersField = ReflectionUtil.getField(executor.getClass(), executor, HashSet.class, "workers"); workers = new HashSet(workersField); // to be able to iterate thread-safely outside the lock } finally { diff --git a/platform/util/src/com/intellij/util/concurrency/SchedulingWrapper.java b/platform/util/src/com/intellij/util/concurrency/SchedulingWrapper.java index 78b522da045d..c62335d62ca8 100644 --- a/platform/util/src/com/intellij/util/concurrency/SchedulingWrapper.java +++ b/platform/util/src/com/intellij/util/concurrency/SchedulingWrapper.java @@ -2,12 +2,11 @@ package com.intellij.util.concurrency; import com.intellij.util.IncorrectOperationException; -import com.intellij.util.containers.ContainerUtil; import org.jetbrains.annotations.NotNull; import java.util.ArrayList; import java.util.Collection; -import java.util.HashSet; +import java.util.Collections; import java.util.List; import java.util.concurrent.*; import java.util.concurrent.atomic.AtomicBoolean; @@ -23,7 +22,7 @@ class SchedulingWrapper implements ScheduledExecutorService { @NotNull final ExecutorService backendExecutorService; final AppDelayQueue delayQueue; - SchedulingWrapper(@NotNull final ExecutorService backendExecutorService, @NotNull AppDelayQueue delayQueue) { + SchedulingWrapper(@NotNull ExecutorService backendExecutorService, @NotNull AppDelayQueue delayQueue) { this.delayQueue = delayQueue; if (backendExecutorService instanceof ScheduledExecutorService) { throw new IllegalArgumentException("backendExecutorService: "+backendExecutorService+" is already ScheduledExecutorService"); @@ -56,15 +55,20 @@ class SchedulingWrapper implements ScheduledExecutorService { @NotNull List cancelAndRemoveTasksFromQueue() { - List result = ContainerUtil.filter(delayQueue, task -> { + List> result = new ArrayList<>(); + for (MyScheduledFutureTask task : delayQueue) { if (task.getBackendExecutorService() == backendExecutorService) { task.cancel(false); - return true; + result.add(task); } - return false; - }); - delayQueue.removeAll(new HashSet<>(result)); - //noinspection unchecked + } + + if (result.isEmpty()) { + return Collections.emptyList(); + } + + delayQueue.removeAll(result); + //noinspection unchecked,rawtypes return (List)result; } @@ -81,8 +85,8 @@ class SchedulingWrapper implements ScheduledExecutorService { @Override public boolean awaitTermination(long timeout, @NotNull TimeUnit unit) throws InterruptedException { if (!isShutdown()) throw new IllegalStateException("must await termination after shutdown() or shutdownNow() only"); - List tasks = new ArrayList<>(delayQueue); - for (MyScheduledFutureTask task : tasks) { + List> tasks = new ArrayList<>(delayQueue); + for (MyScheduledFutureTask task : tasks) { if (task.getBackendExecutorService() != backendExecutorService) { continue; }