未验证 提交 6c3ddfa1 编写于 作者: W Wenjun Ruan 提交者: GitHub

[DS-5559][fix][Master Server] Master Server was shutdown but the process still...

[DS-5559][fix][Master Server] Master Server was shutdown but the process still in system (#5588) (#6048)

* Close spring context to destory beans that has running thread
Co-authored-by: NChouc <32946731+choucmei@users.noreply.github.com>
上级 ba98ff95
...@@ -183,6 +183,8 @@ public class MasterServer implements IStoppable { ...@@ -183,6 +183,8 @@ public class MasterServer implements IStoppable {
} catch (Exception e) { } catch (Exception e) {
logger.warn("Quartz service stopped exception:{}", e.getMessage()); logger.warn("Quartz service stopped exception:{}", e.getMessage());
} }
// close spring Context and will invoke method with @PreDestroy annotation to destory beans. like ServerNodeManager,HostManager,TaskResponseService,CuratorZookeeperClient,etc
springApplicationContext.close();
} catch (Exception e) { } catch (Exception e) {
logger.error("master server stop exception ", e); logger.error("master server stop exception ", e);
} }
......
...@@ -163,6 +163,7 @@ public class WorkerServer implements IStoppable { ...@@ -163,6 +163,7 @@ public class WorkerServer implements IStoppable {
// close // close
this.nettyRemotingServer.close(); this.nettyRemotingServer.close();
this.workerRegistry.unRegistry(); this.workerRegistry.unRegistry();
this.springApplicationContext.close();
} catch (Exception e) { } catch (Exception e) {
logger.error("worker server stop exception ", e); logger.error("worker server stop exception ", e);
} }
......
...@@ -49,6 +49,7 @@ public class RetryReportTaskStatusThread implements Runnable { ...@@ -49,6 +49,7 @@ public class RetryReportTaskStatusThread implements Runnable {
public void start(){ public void start(){
Thread thread = new Thread(this,"RetryReportTaskStatusThread"); Thread thread = new Thread(this,"RetryReportTaskStatusThread");
thread.setDaemon(true);
thread.start(); thread.start();
} }
......
...@@ -19,6 +19,7 @@ package org.apache.dolphinscheduler.service.bean; ...@@ -19,6 +19,7 @@ package org.apache.dolphinscheduler.service.bean;
import org.springframework.beans.BeansException; import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware; import org.springframework.context.ApplicationContextAware;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@Component @Component
...@@ -31,7 +32,14 @@ public class SpringApplicationContext implements ApplicationContextAware { ...@@ -31,7 +32,14 @@ public class SpringApplicationContext implements ApplicationContextAware {
SpringApplicationContext.applicationContext = applicationContext; SpringApplicationContext.applicationContext = applicationContext;
} }
public static <T> T getBean(Class<T> requiredType){ /**
* Close this application context, destroying all beans in its bean factory.
*/
public void close() {
((AbstractApplicationContext)applicationContext).close();
}
public static <T> T getBean(Class<T> requiredType) {
return applicationContext.getBean(requiredType); return applicationContext.getBean(requiredType);
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册