Calling a function every 10 minutes

前端 未结 5 2172
有刺的猬
有刺的猬 2020-12-05 14:05

I\'m not an expert, just a beginner. So I kindly ask that you write some code for me.

If I have two classes, CLASS A and CLASS B, and insid

5条回答
  •  独厮守ぢ
    2020-12-05 14:37

    Solution with Java 8

    ClassB b = new ClassB();    
    ScheduledExecutorService executor = Executors.newScheduledThreadPool(1);
    Runnable task = () -> {
        b.funb();
    };
    executor.scheduleWithFixedDelay(task, 0, 10, TimeUnit.MINUTES);
    

提交回复
热议问题