6
से प्रतिक्रिया के रूप में भविष्य को संभालना भविष्य में यह कोड है जो काम करता है। यह एक अभिनेता (ग्रीटर) को एक संदेश भेजता है और जवाब का इंतजार कर रहा है। लेकिन यह वर्तमान धागे को अवरुद्ध करता है।अक्का अभिनेता
public class Future1Blocking {
public static void main(String[] args) throws Exception {
ActorSystem system = ActorSystem.create("system");
final ActorRef actorRef = system.actorOf(Props.create(Greeter.class), "greeter");
Timeout timeout = new Timeout(Duration.create(5, "seconds"));
Future<Object> future = Patterns.ask(actorRef, Greeter.Msg.GREET, timeout);
// this blocks current running thread
Greeter.Msg result = (Greeter.Msg) Await.result(future, timeout.duration());
System.out.println(result);
}
}
मेरी उदाहरण future.onSuccess
उपयोग करने के लिए वर्तमान कॉल की धागा को रोके बिना परिणाम प्राप्त करने के लिए संभव तरीका क्या है?