w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
What is the best way to stop execution for few seconds in java?

Your code looks ok and should work. But you need to make sure that the boolean value passed by personService.isOverLoaded() is volatile.

Volatile will make sure that value of this boolean flag is not cached by your processing thread.

   private volatile boolean flag = false;

    public void overLoaded(){
       flag = true; // based on some condition
    }

    public boolean isOverLoaded(){
        return flag; // Accessed in your thread
    }




© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.