Tags
- oracle
- postman
- postman html parse
- Android/iOS Developer
- UI/UX Engineer
- LSL_Script
- Android
- Intellij
- postman collection
- Unity
- emplace_back
- postman pre-request
- postman automations
- Java
- Front-end developer
- c#
- MFC
- postman collection variables
- web developer
- postman excel
- postman tests
- solidity
- 다빈치 리졸브
- 프런트엔드
- C++
- 우수한 프런트 개발자
- postman csv
- 좋은 개발자
- Interaction developer
- postman session
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Archives
- Today
- Total
david's daily developer note
[BE] 일정 시간 후에 수행하는 조각 코드 java 본문
728x90
아래 코드는 일정 시간 이후에 비동기적인 작업 수행이 필요할 때 사용한다.
private void close(String reason) {
new java.util.Timer().schedule(new java.util.TimerTask() {
@Override
public void run() {
reconnect();
}
}, 5000); // Delay in milliseconds
}
private void reconnect() {
//say something
}
1. Timer 인스턴스를 생성하고 백그라운드 스레드를 활용 예약된 작업을 실행
1. TimerTask 추상 클래스를 재정의하여 schedule()함수의 첫 번째 실행 작업 인자로 던져준다.
6. schedule() 함수의 두 번째 인자는 작업이 실행전 대기 시간이다.
상기 코드를 활용하면, 메인 스레드와 별개로 비동기적 작업을 수행할 수 있다.
728x90
'[Develop] Web > Back-end' 카테고리의 다른 글
[BE] Slack API - Log notice (0) | 2025.04.14 |
---|---|
[BE] CRC Error Resolved in IntelliJ Gradle Project (0) | 2025.02.11 |
[BE] SpringBoot 3.2.3 developer tools simple note (0) | 2024.03.19 |
[BE] Spring security AuthenticationSuccessEvent & SessionDestroyedEvent (0) | 2023.10.30 |
[BE] IntelliJ + MariaDB Local Setting (1) | 2023.10.24 |