Karthik Suresh
Karthik Suresh

Reputation: 407

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?

Upvotes: 3

Views: 90

Answers (1)

YK S
YK S

Reputation: 3430

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.

Upvotes: 3

Related Questions