简体   繁体   English

Java程序执行线程

[英]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). 当java程序执行从控制器一直到DAO层开始时,在我之间我想暂停执行,直到某些其他模型发生一些繁重的操作(Post请求做一些操作)。 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? 我们可以暂停当前进程执行,然后在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: 您可以在IMO中使用CompletableFuture执行其他操作并等待它完成,如下所示:

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. 现在, future.get()用于检索计算结果,因此它将一直阻塞,直到o / p不可用为止,一旦它出现就会继续。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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