Commit 8c195b02 by huangfusuper

【修改BUG】修正偶发性死锁的问题

parent 49bc071d
...@@ -7,4 +7,6 @@ misc.xml ...@@ -7,4 +7,6 @@ misc.xml
modules.xml modules.xml
Project_Default.xml Project_Default.xml
vcs.xml vcs.xml
workspace.xml workspace.xml
\ No newline at end of file
target
\ No newline at end of file
...@@ -32,7 +32,8 @@ public class MythJobScheduler implements InitializingBean, DisposableBean { ...@@ -32,7 +32,8 @@ public class MythJobScheduler implements InitializingBean, DisposableBean {
*/ */
@Override @Override
public void destroy() throws Exception { public void destroy() throws Exception {
this.jobScheduleHelper.doStop();
this.logScanHelper.doStop();
} }
/** /**
...@@ -42,8 +43,8 @@ public class MythJobScheduler implements InitializingBean, DisposableBean { ...@@ -42,8 +43,8 @@ public class MythJobScheduler implements InitializingBean, DisposableBean {
@Override @Override
public void afterPropertiesSet() throws Exception { public void afterPropertiesSet() throws Exception {
//启用扫描线程 //启用扫描线程
jobScheduleHelper.start(); this.jobScheduleHelper.start();
logScanHelper.start(); this.logScanHelper.start();
} }
} }
...@@ -320,6 +320,43 @@ public class JobScheduleHelper{ ...@@ -320,6 +320,43 @@ public class JobScheduleHelper{
scheduleThread.setDaemon(true); scheduleThread.setDaemon(true);
scheduleThread.start(); scheduleThread.start();
} }
public void doStop(){
this.jobInfoThreadToStop = true;
try {
TimeUnit.SECONDS.sleep(1);
} catch (InterruptedException e) {
e.printStackTrace( );
}
if (jobInfoThread.getState() != Thread.State.TERMINATED) {
jobInfoThread.interrupt();
try {
jobInfoThread.join();
} catch (InterruptedException e) {
e.printStackTrace( );
}
}
log.warn("---------------【任务节点节点扫描线程被注销】-----------------------");
this.scheduleThreadToStop = true;
try {
TimeUnit.SECONDS.sleep(1);
} catch (InterruptedException e) {
e.printStackTrace( );
}
if (scheduleThread.getState() != Thread.State.TERMINATED) {
scheduleThread.interrupt();
try {
scheduleThread.join();
} catch (InterruptedException e) {
e.printStackTrace( );
}
}
log.warn("---------------【排期表扫描线程被注销】-----------------------");
}
@Autowired @Autowired
public void setDataSource(DataSource dataSource) { public void setDataSource(DataSource dataSource) {
......
...@@ -110,7 +110,43 @@ public class LogScanHelper { ...@@ -110,7 +110,43 @@ public class LogScanHelper {
e.printStackTrace(); e.printStackTrace();
}finally { }finally {
//释放资源 //释放资源
freedResource(conn,preparedStatement,connAutoCommit,virtualNodeScanIsStop); if(conn != null){
try {
conn.commit();
} catch (SQLException e) {
if(!virtualNodeScanIsStop){
log.error("--------------------【提交行锁出错】---------------------");
}
}
}
try {
if(conn != null){
conn.setAutoCommit(connAutoCommit);
}
} catch (SQLException e) {
if(!virtualNodeScanIsStop){
log.error("--------------------【恢复自动提交出错】---------------------");
}
}
if(preparedStatement != null){
try {
preparedStatement.close();
} catch (SQLException e) {
if(!notAlarmedNodeScanIsStop){
log.error("--------------------【关闭执行器出错】---------------------");
}
}
}
try {
conn.close();
} catch (SQLException e) {
if(!virtualNodeScanIsStop){
log.error("--------------------【关闭链接出错】---------------------");
}
}
} }
} }
...@@ -136,7 +172,6 @@ public class LogScanHelper { ...@@ -136,7 +172,6 @@ public class LogScanHelper {
conn.setAutoCommit(false); conn.setAutoCommit(false);
preparedStatement = conn.prepareStatement("SELECT * FROM JOB_LOCK WHERE LOCK_NAME = 'log_node_callback_lock' FOR UPDATE "); preparedStatement = conn.prepareStatement("SELECT * FROM JOB_LOCK WHERE LOCK_NAME = 'log_node_callback_lock' FOR UPDATE ");
preparedStatement.execute(); preparedStatement.execute();
System.out.println("--------------火球锁成功------------------" );
//查询的是失败的或者是已经结束的节点(完成的) //查询的是失败的或者是已经结束的节点(完成的)
List<JobTaskRunLog> jobTaskRunLogEndOrFailureNode = jobTaskRunLogService.findJobTaskRunLogEndOrFailureNode( ); List<JobTaskRunLog> jobTaskRunLogEndOrFailureNode = jobTaskRunLogService.findJobTaskRunLogEndOrFailureNode( );
if(CollectionUtil.isNotEmpty(jobTaskRunLogEndOrFailureNode)){ if(CollectionUtil.isNotEmpty(jobTaskRunLogEndOrFailureNode)){
...@@ -184,7 +219,43 @@ public class LogScanHelper { ...@@ -184,7 +219,43 @@ public class LogScanHelper {
}catch (Exception e){ }catch (Exception e){
e.printStackTrace(); e.printStackTrace();
}finally { }finally {
freedResource(conn,preparedStatement,connAutoCommit,notAlarmedNodeScanIsStop); if(conn != null){
try {
conn.commit();
} catch (SQLException e) {
if(!notAlarmedNodeScanIsStop){
log.error("--------------------【提交行锁出错】---------------------");
}
}
}
try {
if(conn != null){
conn.setAutoCommit(connAutoCommit);
}
} catch (SQLException e) {
if(!notAlarmedNodeScanIsStop){
log.error("--------------------【恢复自动提交出错】---------------------");
}
}
if(preparedStatement != null){
try {
preparedStatement.close();
} catch (SQLException e) {
if(!notAlarmedNodeScanIsStop){
log.error("--------------------【关闭执行器出错】---------------------");
}
}
}
try {
conn.close();
} catch (SQLException e) {
if(!notAlarmedNodeScanIsStop){
log.error("--------------------【关闭链接出错】---------------------");
}
}
} }
} }
}); });
...@@ -193,51 +264,6 @@ public class LogScanHelper { ...@@ -193,51 +264,6 @@ public class LogScanHelper {
notAlarmedNodeScanThread.start(); notAlarmedNodeScanThread.start();
} }
/**
* 释放资源
* @param conn 数据库链接
* @param preparedStatement 执行器
* @param connAutoCommit 原来的提交状态
*/
private void freedResource(Connection conn,PreparedStatement preparedStatement,boolean connAutoCommit,boolean isStop){
if(conn != null){
try {
conn.commit();
} catch (SQLException e) {
if(!isStop){
log.error("--------------------【提交行锁出错】---------------------");
}
}
}
try {
assert conn != null;
conn.setAutoCommit(connAutoCommit);
} catch (SQLException e) {
if(!isStop){
log.error("--------------------【恢复自动提交出错】---------------------");
}
}
if(preparedStatement != null){
try {
preparedStatement.close();
} catch (SQLException e) {
if(!isStop){
log.error("--------------------【关闭执行器出错】---------------------");
}
}
}
try {
conn.close();
} catch (SQLException e) {
if(!isStop){
log.error("--------------------【关闭链接出错】---------------------");
}
}
}
public void doStop(){ public void doStop(){
this.virtualNodeScanIsStop = true; this.virtualNodeScanIsStop = true;
...@@ -255,6 +281,7 @@ public class LogScanHelper { ...@@ -255,6 +281,7 @@ public class LogScanHelper {
e.printStackTrace( ); e.printStackTrace( );
} }
} }
log.warn("---------------【虚节点扫描线程被注销】-----------------------");
this.notAlarmedNodeScanIsStop = true; this.notAlarmedNodeScanIsStop = true;
try { try {
...@@ -270,6 +297,8 @@ public class LogScanHelper { ...@@ -270,6 +297,8 @@ public class LogScanHelper {
e.printStackTrace( ); e.printStackTrace( );
} }
} }
log.warn("---------------【日志扫描线程被注销】-----------------------");
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment