简体   繁体   中英

Java program execution thread

When the java program execution starts from controller to all the way till DAO layer, In between i want to halt the execution until some heavy lifting operation happens at some other model(Post request to do some operation). and then resume the task in my current model.

Can we halt the current process execution for sometime and then resume the process in java?

IMO you can make use of CompletableFuture where you want to execute some other operation and wait for it to be completed as shown below:

CompletableFuture<String> future= CompletableFuture.supplyAsync(() -> "Call the function");    
future.get();

Now future.get() is used to retrieve the result of computation so it will block till the o/p is not available and once it is then will proceed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM