Code:
long start = System.currentTimeMillis();
while (true) {
if (System.currentTimeMillis() >= start + 1000) {
doSomethingAt1Second();
start = System.currentTimeMillis();
}
Thread.sleep(10); // prevent CPU overrun usage
}
Also lol @ using nanoTime then erasing the precision. Just use currentTimeMillis boyo
Better options:
Threads if no/minimal shared state (implying sleep, allowing for different execution times)
Scheduled executor service
Simple sleep()
your note about about inefficiency is not true, how could sleep() be inefficient exactly? i'll give you a pass because it's clear you're new because you've never found a use for sleep(). do try to be honest with yourself and not create lies to justify you doing something. when you find a real reason to do delayed calls like this, share it and provide a good example.
i'm sure i could think of a few scenarios where you might be able to use it, but that's not my point. you mention no real world applications. why not share with us why you'd do this opposed to other things? regarding other tutorials, just because someone explains a subject in a way that provides more details you can't find a use for, does not necessarily make it retarded or overly-complicated. you don't cite any resources so it's hard to know exactly what you mean by shutting down any examination.
all in all, there's not enough substance here to really initiate a meaningful discussion.