I need a simple Scheduler and i cant make it work...
im even trying to use CHATGPT but i cant make it work...
Need to start a event at 14:00 20:00 02:00 08:00
I think something like that will do the job:
Consider eventStart() is your event starter:
Import the Calendar:
import java.util.Calendar;
Then set up the event every
final Calendar calendar = Calendar.getInstance();
if ((calendar.get(Calendar.HOUR_OF_DAY) >= 20) && (calendar.get(Calendar.MINUTE) >= 0))
{
calendar.add(Calendar.DAY_OF_YEAR, 1);
}
int _hour = 2; // starts 2am
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
while (_hour <= 20) // runs until 8pm
{
calendar.set(Calendar.HOUR_OF_DAY, _hour);
ThreadPool.scheduleAtFixedRate(() -> eventStart(null), calendar.getTimeInMillis() - System.currentTimeMillis(), 86400000); // 86400000 = 1 day
_hour = _hour + 6;
}
Note: if the server starts after 2am it will schedule for all of the events for starting on the next day.