Java program execution thread

Java program execution thread … here is a solution to the problem.

Java program execution thread

When a java program executes from the Controller all the way up to the DAO layer, I want to stop execution in between until some heavy work happens on other models (posting requests do something). Then resume the task in my current model.

Can we pause the current process execution for a while and then resume it in Java?

Solution

IMO You can use CompletableFuture to do some other things and wait for it to complete as follows:

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

Now future.get() is used to retrieve the calculation result, so it will block until O/P is not available, and continue once available.

Related Problems and Solutions