Skip to content

Commit ad5c409

Browse files
EcljpseB0Tjukzi
authored andcommitted
AntLaunchDelegate.runInSeparateVM: wakeup waiter
I saw in a sampling of building the workspace, that this method slept a multiple of 50ms. Instead the waiting thread can be woken up. For example by using a CountDownLatch
1 parent b6572c8 commit ad5c409

File tree

1 file changed

+12
-7
lines changed
  • ant/org.eclipse.ant.launching/src/org/eclipse/ant/internal/launching/launchConfigurations

1 file changed

+12
-7
lines changed

ant/org.eclipse.ant.launching/src/org/eclipse/ant/internal/launching/launchConfigurations/AntLaunchDelegate.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
import java.util.Iterator;
2727
import java.util.List;
2828
import java.util.Map;
29-
import java.util.concurrent.atomic.AtomicBoolean;
29+
import java.util.concurrent.CountDownLatch;
30+
import java.util.concurrent.TimeUnit;
3031

3132
import org.apache.tools.ant.ProjectHelper;
3233
import org.eclipse.ant.core.AntCorePlugin;
@@ -602,23 +603,27 @@ private void runInSeparateVM(ILaunchConfiguration configuration, ILaunch launch,
602603
refresher.startBackgroundRefresh();
603604
}
604605
} else {
605-
final AtomicBoolean terminated = new AtomicBoolean(false);
606+
final CountDownLatch terminated = new CountDownLatch(1);
606607
IDebugEventSetListener listener = events -> {
607608
for (DebugEvent event : events) {
608609
for (IProcess process : processes) {
609610
if (event.getSource() == process && event.getKind() == DebugEvent.TERMINATE) {
610-
terminated.set(true);
611-
break;
611+
terminated.countDown();
612+
return;
612613
}
613614
}
614615
}
615616
};
616617
DebugPlugin.getDefault().addDebugEventListener(listener);
617-
terminated.compareAndSet(false, launch.isTerminated());
618+
if (launch.isTerminated()) {
619+
terminated.countDown();
620+
}
618621
monitor.subTask(AntLaunchConfigurationMessages.AntLaunchDelegate_28);
619-
while (!monitor.isCanceled() && !terminated.get()) {
622+
while (!monitor.isCanceled()) {
620623
try {
621-
Thread.sleep(50);
624+
if (terminated.await(50, TimeUnit.MILLISECONDS)) {
625+
break;
626+
}
622627
}
623628
catch (InterruptedException e) {
624629
// do nothing

0 commit comments

Comments
 (0)