프로젝트를 진행하다보면 톰켓 shutdown을 실행시켜서 당연히 종료되었다고 생각했지만 제대로 종료되지않고 톰캣 프로세스가 남아있는 현상이 있습니다.

이는 배치 스케쥴링과, JDBC Driver가 종료되지 않을때 나오는 현상인데, shutdown을 시킬때는 배치 스케쥴링과, JDBC Driver를 별도로 강제종료를 시켜줘야 합니다.

 

방법은 다음과 같습니다.

 

 
1. ShutdownHook을 생성
 
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
 
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
 
 
public class ShutdownHook implements ServletContextListener {
    @Override
    public void contextDestroyed(ServletContextEvent arg0)
    {
        try
        {
       
            // 스케쥴러 Bean name을 모를때 주석을 풀어 Bean Name을 찾을 수 있다.
//            String[] temp = getBzRConfigHelper().getFactory().getBeanDefinitionNames();
//            if(temp!=null) {
//                for (int i = 0; i < temp.length; i++) {
//                    this.logHandler("beans : " + temp[i], null);
//                }
//            }    
            // Get a reference to the Scheduler and shut it down
            try {
                Scheduler scheduler = (Scheduler) getBzRConfigHelper().getFactory().getBean("org.springframework.scheduling.quartz.SchedulerFactoryBean");
                scheduler.shutdown(true);        
            }catch(NoSuchBeanDefinitionException e) {
                this.logHandler(e.getMessage(), e);
            }
    
            Enumeration<Driver> drivers = DriverManager.getDrivers();
            while (drivers.hasMoreElements()) {
                Driver driver = drivers.nextElement();
                try {
                    DriverManager.deregisterDriver(driver);
                    this.logHandler(String.format("deregistering jdbc driver: %s", driver), null);
                } catch (SQLException e) {
                    this.logHandler(String.format("deregistering jdbc driver: %s", driver), e);
                }
            }
            Thread.sleep(1000);
            try {
                ThreadGroup threadGroup = Thread.currentThread().getThreadGroup(); 
                threadGroup.interrupt();    
            }catch(Exception e) {
                this.logHandler(e.getMessage(), e);
            }
            this.logHandler("--End contextDestroyed --" + new Date(), null);
            // Sleep for a bit so that we don't get any errors
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
    }
 
    @Override
    public void contextInitialized(ServletContextEvent arg0)
    {
    }
        
    public boolean isNullOrEmpty(String str) {
        return str == null || StringUtils.isEmpty(str);
    }
 
    public boolean isNullOrEmptyOrWhite(String str) {
        return str == null || StringUtils.isEmpty(str.trim());
    }
    
}
http://colorscripter.com/info#e" target="_blank" style="color: rgb(229, 229, 229);">Colored by Color Scripter
http://colorscripter.com/info#e" target="_blank" style="color: white;">cs
 
2. Web.xml 리스너를 생성한 ShutdownHook로 변경
1
2
3
4
5
....
    <listener>
        <listener-class>~.ShutdownHook</listener-class>
    </listener>
http://colorscripter.com/info#e" target="_blank" style="color: rgb(229, 229, 229);">Colored by Color Scripter
http://colorscripter.com/info#e" target="_blank" style="color: white;">cs
 
3. 제대로 톰캣 Process가 종료되는지 확인.
==============================================================================================
주의할점은 각 프로젝트마다 Batch Bean 클래스가 다를 수 있으므로 알맞게 수정해서 사용해야합니다.
by 아카마메 2019. 3. 29. 16:57


JAVA 기본 정책으로 AES128 암호화 방식까지 사용가능하기 때문에,
AES256을 사용하면 아래와 같은 에러가 발생합니다.
java.security.InvalidKeyException: Illegal key size
해결방법은 $JAVA_HOME/jre/lib/security 에 아래의 local_policy.jar US_export_policy.jar 두 파일을 덮어 쓰기 하시면 됩니다.

각 JDK 버전에 맞게 다운로드 받으셔서 덮어 씌워 주셔야 합니다.





by 아카마메 2018. 3. 9. 16:11
| 1 |