code snippet :
// mainclass public class datastreamhandler { future<string> future = executor.submit(new jobconsumer()); try { system.out.println("start future " ); string str = (string) future.get(); } } //thread class public class jobconsumer implements callable { public string call() { //this logic listens stream , return. return "jobconsumer done"; } here, after listening stream, call() returns.
but main thread prints "start future" without call() finishing. how can make sure "start future" printed after call() done?
do know future.get() , returns?
well, first waits task complete , returns value returned task's call method. in case, future.get() return "jobconsumer done".
after these 2 statements:
system.out.println("start future " ); string str = (string) future.get(); you can judge why starts future prints first.
Comments
Post a Comment