diff --git a/java/compiler/impl/src/com/intellij/compiler/server/BuildManager.java b/java/compiler/impl/src/com/intellij/compiler/server/BuildManager.java index 0cc7055c6ae4..4ea275f38e0c 100644 --- a/java/compiler/impl/src/com/intellij/compiler/server/BuildManager.java +++ b/java/compiler/impl/src/com/intellij/compiler/server/BuildManager.java @@ -81,6 +81,7 @@ import java.net.InetSocketAddress; import java.util.*; import java.util.concurrent.Executor; import java.util.concurrent.RejectedExecutionException; +import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; /** @@ -301,14 +302,18 @@ public class BuildManager implements ApplicationComponent{ } } - public void cancelAutoMakeTasks(Project project) { + public Collection cancelAutoMakeTasks(Project project) { + final Collection futures = new ArrayList(); synchronized (myAutomakeFutures) { for (Map.Entry entry : myAutomakeFutures.entrySet()) { if (entry.getValue().equals(project)) { - entry.getKey().cancel(false); + final RequestFuture future = entry.getKey(); + future.cancel(false); + futures.add(future); } } } + return futures; } @Nullable @@ -746,8 +751,17 @@ public class BuildManager implements ApplicationComponent{ }); } + @Override + public boolean canCloseProject(Project project) { + cancelAutoMakeTasks(project); + return super.canCloseProject(project); + } + @Override public void projectClosing(Project project) { + for (RequestFuture future : cancelAutoMakeTasks(project)) { + future.waitFor(500, TimeUnit.MILLISECONDS); + } } @Override