Call method after some delay in java

前端 未结 2 2049
鱼传尺愫
鱼传尺愫 2021-02-20 00:44

Scenario is like :

In my application, I opened one file, updated it and saved. Once the file saved event get fired and it will execute one method abc(). But

2条回答
  •  忘掉有多难
    2021-02-20 01:32

    If you are using Thread.sleep(), just have the static method change a static global variable to something that you can use to indicate blocking the method call?

    public static boolean abcRunning;
    public static void abc()
    {
        if (YourClass.abcRunning == null || !YourClass.abcRunning)
        {
            YourClass.abcRunning = true;
            Thread.Sleep(60000);
            // TODO Your Stuff
            YourClass.abcRunning = false;
        }
    }
    

    Is there any reason this wouldn't work?

提交回复
热议问题