import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
public class Main {
public static void main(String[] args) {
int sleepSec = 10;
final SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
final ScheduledThreadPoolExecutor exec = new ScheduledThreadPoolExecutor(1);
exec.scheduleAtFixedRate(new Runnable() {
public void run() {
try {
Calendar cal = Calendar.getInstance();
System.out.println(sdf.format(cal.getTime()));
} catch (Exception e) {
e.printStackTrace();
exec.shutdown();
}
}
}, 0, sleepSec, TimeUnit.SECONDS);
}
}
ScheduledThreadPoolExecutor - 주기적인 실행
¯¯\_(ツ)_/¯·2018년 2월 1일·조회 2,411
관련 글
- 외부 서비스 웹훅을 로컬에서 테스트하고 서명 검증하기: smee, ngrok, HMAC, 재전송 방어2026년 8월 20일
- Spring Boot @Async 스레드 폭증과 큐 적체 잡기: ThreadPoolTaskExecutor 설정과 MDC 전파2026년 8월 16일
- Git 히스토리에 커밋된 비밀번호와 API 키 완전히 제거하기 (git filter-repo, BFG, gitleaks)2026년 8월 7일
- Python(57868) MallocStackLogging: can't turn off malloc stack logging because it was not enabled. 해결방법2025년 3월 4일
댓글 0
로그인 후 댓글을 남길 수 있습니다.
아직 댓글이 없습니다.