Tags
- postman collection variables
- solidity
- 다빈치 리졸브
- Interaction developer
- LSL_Script
- postman excel
- postman tests
- postman html parse
- postman collection
- c#
- Android/iOS Developer
- Unity
- postman pre-request
- 좋은 개발자
- oracle
- C++
- postman session
- Front-end developer
- Intellij
- emplace_back
- 우수한 프런트 개발자
- Android
- 프런트엔드
- postman
- MFC
- Java
- UI/UX Engineer
- postman csv
- web developer
- postman automations
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
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] 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 |
[BE] 포스트맨 + 엑셀 조합으로 API 실행 자동화 -2 (RSA) (0) | 2023.09.19 |