3

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?

5
  • 4
    Don't use sleep. Read about the wait-notify approach. Commented Apr 5, 2019 at 5:54
  • 4
    You can use wait-notify, semaphores, Future (especially if that heavy op is in background) count down latches etc. Commented Apr 5, 2019 at 5:55
  • what are the heavy operations? Please add those details as well. Commented Apr 5, 2019 at 6:04
  • 1
    @BilboBaggins Retrieving the current status of the inventory with RFC Commented Apr 5, 2019 at 6:12
  • I assume it is going to be a DB call? or an microservice call? Commented Apr 5, 2019 at 6:50

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.