티스토리 뷰
java로 graceful shutdown 구현하기 2탄이다.
https://flowingmooon.tistory.com/5
java로 Graceful shutdown 구현하기
Graceful shutdown이란, 말 그대로 '우아한 끝내기'이다. 프로그램은 잘 돌아가는 것도 중요하지만 잘 죽는 것(?) 또한 중요하다. 어떤 코드를 수행하다 종료 명령이 떨어졌을 때 (ctrl + c) 하던 작업을 잘 마무..
flowingmooon.tistory.com
graceful shutdown을 구현하고 나서 이것이 잘 돌아가는지 확인하려면 ctrl+c (kill signal)을 보내야 한다.
만약 linux 였다면 ctrl+c 를 입력하면 되겠지만 eclipse에서는 ctrl+c가 먹히질 않는다.
해결책은 다음과 같다.
먼저 main()에 아래 코드를 추가해준다.
그리고 eclipse 상위 탭에서
Run - Run Configurations에 들어간다.
그리고 Environment에서 다음과 같은 variable을 만들어 준다.
그리고 run을 하고 console 창을 클릭, enter를 치면 프로그램이 종료된다.
linux에서 ctrl+c를 입력한 것과 동일한 효과를 줄 수 있다.
위 콘솔 창을 보면 종료 signal을 받은 이후에도 프로그램이 하던 일을 모두 수행한 후 프로그램을 종료하는 것을 볼 수 있다.
즉, graceful shutdown이 이루어지고 있는 것이다!
혹시 몰라서 main() 코드를 첨부한다.
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
package dajaba;
import java.io.IOException;
import org.apache.log4j.Logger;
public class DajabaBot {
//public static void startWork(String dataBaseDriverPath, String dataBaseName,Logger logger, DajabaThread exThread) {
//}
public static void main(String[] args) {
Logger logger = Logger.getLogger(DajabaBot.class);
Setting setter = new Setting();
try {
setter.getPropValues();
logger.info("setting is done");
} catch (IOException e) {
logger.error("sth wrong in reading configFile", e);
return;
}
Thread DT = new Thread(new DajabaThread(setter.getProgramCycle(),setter.getDatabaseDriverPath(), setter.getDatabaseName(), setter.getDatabasePath(),setter.getHtmlFilePath(),logger), "DajabaBot");
if (Boolean.parseBoolean(System.getenv("RUNNING_IN_ECLIPSE"))) {
System.out.println("You're using Eclipse; click in this console and " +
"press ENTER to call System.exit() and run the shutdown routine.");
try {
System.in.read();
} catch (IOException e) {
e.printStackTrace();
}
System.exit(0);
}
// ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
// scheduler.scheduleAtFixedRate(new DajabaThread(setter, logger), 0,
// setter.getProgramCycle(), TimeUnit.SECONDS);
}
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
|
github
https://github.com/bluewink/19winter_internship
참고 출처
'PROJECT' 카테고리의 다른 글
java로 Graceful shutdown 구현하기 (0) | 2020.03.30 |
---|---|
AWS로 나만의 서버 만들기 (feat. EC2, PuTTY) (0) | 2020.03.28 |
- Total
- Today
- Yesterday
- 자바
- ec2
- c++
- 코딩테스트
- 카카오
- 프록시
- OOP
- 토비
- 메서드레퍼런스
- 토비의봄TV
- SOLID
- gracefulshutdown
- 서비스추상화
- AOP
- provider
- 데코레이터패턴
- 템플릿콜백
- 백기선
- 스프링
- BOJ
- 코테
- 프록시패턴
- 토비의스프링
- 객체지향
- 김영한
- 예외처리
- 자바스터디
- java
- 프로그래머스
- 디자인패턴
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |