매 초마다 작업을 실행해야하는 스레드를 시작하려고합니다.매 초마다 스레드를 깨우는 방법
// execute my task
..
lastScan.setTime(lastScan.getTime() + 1000);
long timeToSleep = (lastScan.getTime() - new Date().getTime());
try {
Thread.sleep(timeToSleep);
} catch (InterruptedException e) {
e.printStackTrace();
}
이 작동하지만, 뭔가 더 우아하고, 어쩌면 더 안전이 있다면 예를 들어, 내 실 때 깨어 기능을 궁금 해서요 : 지금이 코드에 루프를 만드는에서 한 그래서 현재 날짜가 주어진 시간에 도달합니다.
미리 제안 해 주셔서 감사합니다.
이는 타이머의 용도입니다. – njzk2
[ScheduledExecutorService] (http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/ScheduledExecutorService.html) – GriffeyDog