java - External service fires asynchronous task and immediately returns. How to tell when the tasks are actually finished? -
i need call services , know when finished, can send out notification:
... someservice.dostuff(); otherservice.dostuff(); //all services finished sendoutnotification();
the problem of these services firing off work asynchronously , returning dostuff() immediately, not waiting work finish. since current thread calling these service methods, rather owning actual thread managing executors these services creating , firing, seems there no way know when threads fired dostuff() finished.
is there way around this? or there design issue here chaining asynchronous executions no waiting in level (except top)?
when point must not pass before async work done, need either poll completion of async tasks, or have mechanism blocking on completion.
a decent way approach execute tasks via executorservice
, , provide resulting future
objects main thread handles. is, dostuff()
methods return these. main method collects future
s, , when time comes can poll via future.isdone()
, block on completion via future.get()
, , more.
Comments
Post a Comment