Kill shutdown Thread 적용
This commit is contained in:
parent
2ac5d34bec
commit
3d1f4a9307
@ -53,6 +53,10 @@ public class RunnerConfiguration {
|
|||||||
SmsWriteQueue smsWriteQueue = new SmsWriteQueue(queueInfo);
|
SmsWriteQueue smsWriteQueue = new SmsWriteQueue(queueInfo);
|
||||||
SmsReadQueue smsReadQueue = new SmsReadQueue(queueInfo);
|
SmsReadQueue smsReadQueue = new SmsReadQueue(queueInfo);
|
||||||
QueueServerService queueServerService = new QueueServerService(svc, smsWriteQueue, smsReadQueue);
|
QueueServerService queueServerService = new QueueServerService(svc, smsWriteQueue, smsReadQueue);
|
||||||
|
|
||||||
|
ShutdownService shutdownService = new ShutdownService(queueServerService);
|
||||||
|
Runtime.getRuntime().addShutdownHook(shutdownService);
|
||||||
|
|
||||||
queueServerService.start();
|
queueServerService.start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -80,6 +84,10 @@ public class RunnerConfiguration {
|
|||||||
LmsWriteQueue lmsWriteQueue = new LmsWriteQueue(queueInfo);
|
LmsWriteQueue lmsWriteQueue = new LmsWriteQueue(queueInfo);
|
||||||
LmsReadQueue lmsReadQueue = new LmsReadQueue(queueInfo);
|
LmsReadQueue lmsReadQueue = new LmsReadQueue(queueInfo);
|
||||||
QueueServerService queueServerService = new QueueServerService(svc, lmsWriteQueue, lmsReadQueue);
|
QueueServerService queueServerService = new QueueServerService(svc, lmsWriteQueue, lmsReadQueue);
|
||||||
|
|
||||||
|
ShutdownService shutdownService = new ShutdownService(queueServerService);
|
||||||
|
Runtime.getRuntime().addShutdownHook(shutdownService);
|
||||||
|
|
||||||
queueServerService.start();
|
queueServerService.start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -107,6 +115,10 @@ public class RunnerConfiguration {
|
|||||||
MmsWriteQueue mmsWriteQueue = new MmsWriteQueue(queueInfo);
|
MmsWriteQueue mmsWriteQueue = new MmsWriteQueue(queueInfo);
|
||||||
MmsReadQueue mmsReadQueue = new MmsReadQueue(queueInfo);
|
MmsReadQueue mmsReadQueue = new MmsReadQueue(queueInfo);
|
||||||
QueueServerService queueServerService = new QueueServerService(svc, mmsWriteQueue, mmsReadQueue);
|
QueueServerService queueServerService = new QueueServerService(svc, mmsWriteQueue, mmsReadQueue);
|
||||||
|
|
||||||
|
ShutdownService shutdownService = new ShutdownService(queueServerService);
|
||||||
|
Runtime.getRuntime().addShutdownHook(shutdownService);
|
||||||
|
|
||||||
queueServerService.start();
|
queueServerService.start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -134,6 +146,10 @@ public class RunnerConfiguration {
|
|||||||
KakaoAlarmWriteQueue katWriteQueue = new KakaoAlarmWriteQueue(queueInfo);
|
KakaoAlarmWriteQueue katWriteQueue = new KakaoAlarmWriteQueue(queueInfo);
|
||||||
KakaoAlarmReadQueue katReadQueue = new KakaoAlarmReadQueue(queueInfo);
|
KakaoAlarmReadQueue katReadQueue = new KakaoAlarmReadQueue(queueInfo);
|
||||||
QueueServerService queueServerService = new QueueServerService(svc, katWriteQueue, katReadQueue);
|
QueueServerService queueServerService = new QueueServerService(svc, katWriteQueue, katReadQueue);
|
||||||
|
|
||||||
|
ShutdownService shutdownService = new ShutdownService(queueServerService);
|
||||||
|
Runtime.getRuntime().addShutdownHook(shutdownService);
|
||||||
|
|
||||||
queueServerService.start();
|
queueServerService.start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -161,6 +177,10 @@ public class RunnerConfiguration {
|
|||||||
KakaoFriendWriteQueue kftWriteQueue = new KakaoFriendWriteQueue(queueInfo);
|
KakaoFriendWriteQueue kftWriteQueue = new KakaoFriendWriteQueue(queueInfo);
|
||||||
KakaoFriendReadQueue kftReadQueue = new KakaoFriendReadQueue(queueInfo);
|
KakaoFriendReadQueue kftReadQueue = new KakaoFriendReadQueue(queueInfo);
|
||||||
QueueServerService queueServerService = new QueueServerService(svc, kftWriteQueue, kftReadQueue);
|
QueueServerService queueServerService = new QueueServerService(svc, kftWriteQueue, kftReadQueue);
|
||||||
|
|
||||||
|
ShutdownService shutdownService = new ShutdownService(queueServerService);
|
||||||
|
Runtime.getRuntime().addShutdownHook(shutdownService);
|
||||||
|
|
||||||
queueServerService.start();
|
queueServerService.start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -180,6 +200,10 @@ public class RunnerConfiguration {
|
|||||||
int port = serverConfig.getInt(serviceName + ".SERVICE_PORT");
|
int port = serverConfig.getInt(serviceName + ".SERVICE_PORT");
|
||||||
// CollectBackServerService collectServerService = new CollectBackServerService(serviceName, serviceType, port);
|
// CollectBackServerService collectServerService = new CollectBackServerService(serviceName, serviceType, port);
|
||||||
CollectServer collectServer = new CollectServer(serviceName, serviceType, port);
|
CollectServer collectServer = new CollectServer(serviceName, serviceType, port);
|
||||||
|
|
||||||
|
ShutdownService shutdownService = new ShutdownService(collectServer);
|
||||||
|
Runtime.getRuntime().addShutdownHook(shutdownService);
|
||||||
|
|
||||||
collectServer.start();
|
collectServer.start();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
@ -196,6 +220,10 @@ public class RunnerConfiguration {
|
|||||||
int port = serverConfig.getInt(serviceName + ".SERVICE_PORT");
|
int port = serverConfig.getInt(serviceName + ".SERVICE_PORT");
|
||||||
// CollectBackServerService collectServerService = new CollectBackServerService(serviceName, serviceType, port);
|
// CollectBackServerService collectServerService = new CollectBackServerService(serviceName, serviceType, port);
|
||||||
CollectServer collectServer = new CollectServer(serviceName, serviceType, port);
|
CollectServer collectServer = new CollectServer(serviceName, serviceType, port);
|
||||||
|
|
||||||
|
ShutdownService shutdownService = new ShutdownService(collectServer);
|
||||||
|
Runtime.getRuntime().addShutdownHook(shutdownService);
|
||||||
|
|
||||||
collectServer.start();
|
collectServer.start();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
@ -212,6 +240,10 @@ public class RunnerConfiguration {
|
|||||||
int port = serverConfig.getInt(serviceName + ".SERVICE_PORT");
|
int port = serverConfig.getInt(serviceName + ".SERVICE_PORT");
|
||||||
// CollectBackServerService collectServerService = new CollectBackServerService(serviceName, serviceType, port);
|
// CollectBackServerService collectServerService = new CollectBackServerService(serviceName, serviceType, port);
|
||||||
CollectServer collectServer = new CollectServer(serviceName, serviceType, port);
|
CollectServer collectServer = new CollectServer(serviceName, serviceType, port);
|
||||||
|
|
||||||
|
ShutdownService shutdownService = new ShutdownService(collectServer);
|
||||||
|
Runtime.getRuntime().addShutdownHook(shutdownService);
|
||||||
|
|
||||||
collectServer.start();
|
collectServer.start();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
@ -228,6 +260,10 @@ public class RunnerConfiguration {
|
|||||||
int port = serverConfig.getInt(serviceName + ".SERVICE_PORT");
|
int port = serverConfig.getInt(serviceName + ".SERVICE_PORT");
|
||||||
// CollectBackServerService collectServerService = new CollectBackServerService(serviceName, serviceType, port);
|
// CollectBackServerService collectServerService = new CollectBackServerService(serviceName, serviceType, port);
|
||||||
CollectServer collectServer = new CollectServer(serviceName, serviceType, port);
|
CollectServer collectServer = new CollectServer(serviceName, serviceType, port);
|
||||||
|
|
||||||
|
ShutdownService shutdownService = new ShutdownService(collectServer);
|
||||||
|
Runtime.getRuntime().addShutdownHook(shutdownService);
|
||||||
|
|
||||||
collectServer.start();
|
collectServer.start();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
@ -244,6 +280,10 @@ public class RunnerConfiguration {
|
|||||||
int port = serverConfig.getInt(serviceName + ".SERVICE_PORT");
|
int port = serverConfig.getInt(serviceName + ".SERVICE_PORT");
|
||||||
// CollectBackServerService collectServerService = new CollectBackServerService(serviceName, serviceType, port);
|
// CollectBackServerService collectServerService = new CollectBackServerService(serviceName, serviceType, port);
|
||||||
CollectServer collectServer = new CollectServer(serviceName, serviceType, port);
|
CollectServer collectServer = new CollectServer(serviceName, serviceType, port);
|
||||||
|
|
||||||
|
ShutdownService shutdownService = new ShutdownService(collectServer);
|
||||||
|
Runtime.getRuntime().addShutdownHook(shutdownService);
|
||||||
|
|
||||||
collectServer.start();
|
collectServer.start();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
@ -258,6 +298,10 @@ public class RunnerConfiguration {
|
|||||||
String serviceName = "REPORTER";
|
String serviceName = "REPORTER";
|
||||||
int port = serverConfig.getInt(serviceName + ".SERVICE_PORT");
|
int port = serverConfig.getInt(serviceName + ".SERVICE_PORT");
|
||||||
ReportServer reportServer = new ReportServer(serviceName, port);
|
ReportServer reportServer = new ReportServer(serviceName, port);
|
||||||
|
|
||||||
|
ShutdownService shutdownService = new ShutdownService(reportServer);
|
||||||
|
Runtime.getRuntime().addShutdownHook(shutdownService);
|
||||||
|
|
||||||
reportServer.start();
|
reportServer.start();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
@ -271,6 +315,10 @@ public class RunnerConfiguration {
|
|||||||
try {
|
try {
|
||||||
String serviceName = "REPORT_QUEUE";
|
String serviceName = "REPORT_QUEUE";
|
||||||
ReportQueueServer reportQueueServer = new ReportQueueServer(serviceName);
|
ReportQueueServer reportQueueServer = new ReportQueueServer(serviceName);
|
||||||
|
|
||||||
|
ShutdownService shutdownService = new ShutdownService(reportQueueServer);
|
||||||
|
Runtime.getRuntime().addShutdownHook(shutdownService);
|
||||||
|
|
||||||
reportQueueServer.start();
|
reportQueueServer.start();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
@ -284,6 +332,10 @@ public class RunnerConfiguration {
|
|||||||
try {
|
try {
|
||||||
String serviceName = "HEALTH";
|
String serviceName = "HEALTH";
|
||||||
HealthCheckServer healthCheckServer = new HealthCheckServer(serviceName);
|
HealthCheckServer healthCheckServer = new HealthCheckServer(serviceName);
|
||||||
|
|
||||||
|
ShutdownService shutdownService = new ShutdownService(healthCheckServer);
|
||||||
|
Runtime.getRuntime().addShutdownHook(shutdownService);
|
||||||
|
|
||||||
healthCheckServer.start();
|
healthCheckServer.start();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
|
|||||||
@ -72,7 +72,10 @@ public class CollectServer extends Service {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void closeCollectChannel() throws IOException {
|
private void closeCollectChannel() throws IOException {
|
||||||
selector.close();
|
if (selector != null) {
|
||||||
|
selector.close();
|
||||||
|
selector = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@ -16,11 +16,17 @@ public abstract class Service extends Thread {
|
|||||||
protected LogUtil logger;
|
protected LogUtil logger;
|
||||||
private Long LAST_PROPERTY_LOAD_TIME = 0L;
|
private Long LAST_PROPERTY_LOAD_TIME = 0L;
|
||||||
|
|
||||||
|
/** 서비스 종료여부를 체크하는 변수 */
|
||||||
|
boolean bEndProcess = false;
|
||||||
|
|
||||||
protected boolean IS_SERVER_RUN; // 서버가 구동중인지 여부
|
protected boolean IS_SERVER_RUN; // 서버가 구동중인지 여부
|
||||||
protected boolean IS_READY_YN; // 서비스 구동준비가 완료되었는지 체크
|
protected boolean IS_READY_YN; // 서비스 구동준비가 완료되었는지 체크
|
||||||
protected boolean IS_RUN_YN;
|
protected boolean IS_RUN_YN;
|
||||||
protected boolean IS_STOP_YN;
|
protected boolean IS_STOP_YN;
|
||||||
|
|
||||||
|
/** SERVICE KILL SYGNAL IS RECEIVED */
|
||||||
|
protected boolean IS_KILL_YN = false;
|
||||||
|
|
||||||
public Service() {}
|
public Service() {}
|
||||||
public Service(String serviceName) {
|
public Service(String serviceName) {
|
||||||
super(serviceName);
|
super(serviceName);
|
||||||
@ -52,7 +58,7 @@ public abstract class Service extends Thread {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean isRun() {
|
public boolean isRun() {
|
||||||
return IS_SERVER_RUN && IS_RUN_YN && !IS_STOP_YN;
|
return IS_SERVER_RUN && IS_RUN_YN && !IS_STOP_YN && !IS_KILL_YN;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isReady() {
|
public boolean isReady() {
|
||||||
@ -99,7 +105,8 @@ public abstract class Service extends Thread {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
while (true) {
|
while (!IS_KILL_YN) {
|
||||||
|
IS_STOP_YN = false;
|
||||||
try {
|
try {
|
||||||
/* 1. 서비스간의 dependency에 따른 체크 */
|
/* 1. 서비스간의 dependency에 따른 체크 */
|
||||||
checkReady();
|
checkReady();
|
||||||
@ -122,10 +129,75 @@ public abstract class Service extends Thread {
|
|||||||
/* 6. 3초간 sleep */
|
/* 6. 3초간 sleep */
|
||||||
Thread.sleep(3000);
|
Thread.sleep(3000);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
IS_STOP_YN = true;
|
||||||
saveSystemLog(e);
|
saveSystemLog(e);
|
||||||
} finally {
|
} finally {
|
||||||
if(logger != null) { logger.close(); logger = null; }
|
if(logger != null) { logger.close(); logger = null; }
|
||||||
|
/* Exception 발생 대비 자원 해제 */
|
||||||
|
releaseResources();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(!IS_KILL_YN) {
|
||||||
|
try {
|
||||||
|
Thread.sleep(3000);
|
||||||
|
} catch(Exception e) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
stopService();
|
||||||
|
} catch (Exception e) {
|
||||||
|
|
||||||
|
}
|
||||||
|
bEndProcess = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized void Start() {
|
||||||
|
super.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected synchronized void Stop() {
|
||||||
|
IS_STOP_YN = true;
|
||||||
|
saveSystemLog("Service Stoping...");
|
||||||
|
}
|
||||||
|
|
||||||
|
protected synchronized void kill() {
|
||||||
|
if( !IS_KILL_YN ) saveSystemLog("Service Killing...");
|
||||||
|
|
||||||
|
IS_KILL_YN = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void startService() throws Exception {
|
||||||
|
saveLog("startService() called.");
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void stopService() throws Exception {
|
||||||
|
saveLog("stopService() called.");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void stopThread() {
|
||||||
|
bEndProcess = true;
|
||||||
|
kill();
|
||||||
|
|
||||||
|
int i=0;
|
||||||
|
while(true) {
|
||||||
|
try {
|
||||||
|
Thread.sleep(1*1000);
|
||||||
|
} catch(InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(bEndProcess) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.interrupt();
|
||||||
|
try {
|
||||||
|
Thread.sleep(100);
|
||||||
|
} catch(InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -0,0 +1,15 @@
|
|||||||
|
package com.munjaon.server.server.service;
|
||||||
|
|
||||||
|
public class ShutdownService extends Thread {
|
||||||
|
private Service service = null;
|
||||||
|
|
||||||
|
public ShutdownService(Service service) {
|
||||||
|
super();
|
||||||
|
this.service = service;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
service.stopThread();
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user