|
26 | 26 | import java.util.Iterator;
|
27 | 27 | import java.util.List;
|
28 | 28 | import java.util.Map;
|
29 |
| -import java.util.concurrent.atomic.AtomicBoolean; |
| 29 | +import java.util.concurrent.CountDownLatch; |
| 30 | +import java.util.concurrent.TimeUnit; |
30 | 31 |
|
31 | 32 | import org.apache.tools.ant.ProjectHelper;
|
32 | 33 | import org.eclipse.ant.core.AntCorePlugin;
|
@@ -602,23 +603,27 @@ private void runInSeparateVM(ILaunchConfiguration configuration, ILaunch launch,
|
602 | 603 | refresher.startBackgroundRefresh();
|
603 | 604 | }
|
604 | 605 | } else {
|
605 |
| - final AtomicBoolean terminated = new AtomicBoolean(false); |
| 606 | + final CountDownLatch terminated = new CountDownLatch(1); |
606 | 607 | IDebugEventSetListener listener = events -> {
|
607 | 608 | for (DebugEvent event : events) {
|
608 | 609 | for (IProcess process : processes) {
|
609 | 610 | if (event.getSource() == process && event.getKind() == DebugEvent.TERMINATE) {
|
610 |
| - terminated.set(true); |
611 |
| - break; |
| 611 | + terminated.countDown(); |
| 612 | + return; |
612 | 613 | }
|
613 | 614 | }
|
614 | 615 | }
|
615 | 616 | };
|
616 | 617 | DebugPlugin.getDefault().addDebugEventListener(listener);
|
617 |
| - terminated.compareAndSet(false, launch.isTerminated()); |
| 618 | + if (launch.isTerminated()) { |
| 619 | + terminated.countDown(); |
| 620 | + } |
618 | 621 | monitor.subTask(AntLaunchConfigurationMessages.AntLaunchDelegate_28);
|
619 |
| - while (!monitor.isCanceled() && !terminated.get()) { |
| 622 | + while (!monitor.isCanceled()) { |
620 | 623 | try {
|
621 |
| - Thread.sleep(50); |
| 624 | + if (terminated.await(50, TimeUnit.MILLISECONDS)) { |
| 625 | + break; |
| 626 | + } |
622 | 627 | }
|
623 | 628 | catch (InterruptedException e) {
|
624 | 629 | // do nothing
|
|
0 commit comments