java - What is the most passive way to create a timer loop? -


for of need know, i'm writing plugin craftbukkit, modded version of minecraft, , i'm beginner level java programmer. have think basic question.

i'm trying implement countdown executes methods send messages players every second 20 seconds.

obviously, can't create loop loops 20 seconds, because loop freeze main thread until finishes, unacceptable. (there lot of game code executing)

what approaches creating loop run passively or without halting main thread?

the thing can possibly think creating new thread run countdown in. surely there simpler way this?

so aren't confused, countdown isn't initialized part of main loop, initialized linearly user command listener, code executes in main loop. mean need start loop checks time, because code executed once.

sorry if i'm not being clear or making sense.

i recommend java.util.timer if not using swing gui/graphics (not familiar craftbukkit, determine). in particular, @ forms of schedule allow task repeated @ fixed intervals.

javax.swing.timer similar. biggest difference (aside interfaces used respond timers being triggered) javax.swing.timer utilizes edt (event dispatch thread) run events. if you're using swing gui, thread present , running , want use it. if you're not using swing or awt, overhead don't need.


Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -