I am looking for a blocking version of AtomicReference
to avoid such active waiting:
AtomicReference<Object> ref = new AtomicReference<Object>();
// execute some code in a different thread and set the reference
Object o;
while ((o = ref.get()) == null);
// continue execution
Java provides a Future
interface, which blocks in get()
method. But I cannot use that part of concurrent
package because the reference should be set by a framework where the usage of a simple listener is expected.
To be more precise I work with the launching framework in Eclipse. I fire a maven launch via org.eclipse.m2e.actions.ExecutePomAction
but I don't have a directly access to its process because it's hidden deeply in JDT. That's why I'm using Eclipse's launch manager for that purpose:
final ILaunchManager launchMan = DebugPlugin.getDefault().getLaunchManager();
launchMan.addLaunchListener(new ILaunchListener() {
public void launchRemoved(ILaunch launch) {
ILaunchConfiguration conf = launch.getLaunchConfiguration();
if (("Executing install in "+proj.getLocation().toOSString().replace('\\', '-')).equals(conf.getName()))
{
IProcess[] processes = launch.getProcesses();
if (processes.length == 1)
procRef.set(processes[0]);
}
launchMan.removeLaunchListener(this);
}
});
I think there is no other way to use active waiting afterwards, because IProcess provides no possibility to listen on its termination. Kinda like this:
BusyIndicator.showWhile(Display.getCurrent(), new Runnable() {
public void run() {
while (!proc.isTerminated())
Thread.sleep(500);
}
});
This question has basically something common with [eclipse pde]How to catch the event that a launch is terminated? but it's quite old and I provided here more information on my investigations.
You can use DebugPlugin.getDefault().addDebugEventFilter(filter)
to set up an IDebugEventFilter
class.
This is given all the debug / run events include the DebugEvent.TERMINATE
event when a launch terminates.