How to call function every hour? Also, how can I loop this?

前端 未结 4 1109
鱼传尺愫
鱼传尺愫 2021-02-05 14:17

I need a simple way to call a function every 60 minutes. How can I do this? I\'m making a MineCraft bukkit plugin, and this is what I have:

package com.webs.play         


        
4条回答
  •  广开言路
    2021-02-05 14:20

    Create a thread that will run forever and wakes up every hour to execute your data.

    Thread t = new Thread() {
        @Override
        public void run() {
            while(true) {
                try {
                    Thread.sleep(1000*60*60);
                    //your code here...
                } catch (InterruptedException ie) {
                }
            }
        }
    };
    t.start();
    

提交回复
热议问题