It's being called every second because you're sleeping for 1000 milliseconds, aka 1 second.
Change it to Thread.sleep(10000)
and that'll be better for you.
Alternatively, use
Thread.sleep(TimeUnit.SECONDS.toMillis(10));
which means you don't have to do the arithmetic yourself. (Many APIs now take a quantity and a TimeUnit
, but there doesn't appear to be anything like that for Thread.sleep
unfortunately.)
Note that this will make the thread unresponsive for 10 seconds, with no clean way of telling it to wake up (e.g. because you want to shut it down). I generally prefer to use wait()
so that I can pulse the same monitor from a different thread to indicate "I want you to wake up now!" This is usually from within a while loop of the form
while (!shouldStop())
EDIT: tvanfosson's solution of using a Timer
is also good - and another alternative is to use ScheduledExecutorService
which can be a bit more flexible (and easier to test).