您可以在另一个线程中等待并使用回调来通知“原始”线程或对象对命名服务的请求已解决。
class WaitThread extends Thread {
CallBackObj callback;
public WaitThread(CallBackObj callback) {
this.text = callback;
// assume CORBA stuff initiated here
}
public void run() {
Object expectedObj = null;
do
{
try { expectedObj = ncRef.resolve_str("expectedToBeInNameService"); }
catch (NotFound e) {}
Thread.sleep(2000);
} while(expectedObj == null;
callback.notifyMethodExample();
}
}
调用者必须实现接口 CallBackObj 并将通过
WaitThread wt = new WaitThread(this);
wt.start();
interface CallBackObj {
void notifyMethodExample();
}