Execute a method in java to check the time and execute a method on certain times
<p>I'm running an IRC bot and it needs to echo a message in the chat between two set hours and do this every few minutes : </p>

<p>I tried to do : </p>

<pre><code>        public void timerTest(int minH,int maxH, int minT){
        boolean b = true;
        boolean timeout = false;
        while(b){
            while(!timeout){
                if(c.get(Calendar.HOUR_OF_DAY) &gt;= minH &amp;&amp; c.get(Calendar.HOUR_OF_DAY) &lt;= maxH &amp;&amp; c.get(Calendar.MINUTE) % minT == 0){   
                    sendMessage(channel,spam1.getMessage());
                    timeout = true;
                  }
                }
                if(c.get(Calendar.MINUTE)%minT == 1){
                    timeout = false;
                }
            }
        }
</code></pre>

<p>I normally want to spam a message every 15 minutes between 2 and 6. I tried putting it in an unendless while loop, but this is not recommended. I looked for Timer and TimerTask but I can't figure out how to properly do it. If someone would be so kind to explain how I can achieve this ? </p>

<p>thank you ^^</p>
