Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
byit-myth-job
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
liyuan
byit-myth-job
Commits
8c195b02
Commit
8c195b02
authored
Jan 02, 2020
by
huangfusuper
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
【修改BUG】修正偶发性死锁的问题
parent
49bc071d
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
97 additions
and
27 deletions
+97
-27
.gitignore
.gitignore
+3
-0
MythJobScheduler.java
...in-core/src/main/java/com/byit/conf/MythJobScheduler.java
+4
-3
JobScheduleHelper.java
...core/src/main/java/com/byit/thread/JobScheduleHelper.java
+37
-0
LogScanHelper.java
...min-core/src/main/java/com/byit/thread/LogScanHelper.java
+53
-24
No files found.
.gitignore
View file @
8c195b02
...
@@ -8,3 +8,5 @@ modules.xml
...
@@ -8,3 +8,5 @@ modules.xml
Project_Default.xml
Project_Default.xml
vcs.xml
vcs.xml
workspace.xml
workspace.xml
target
\ No newline at end of file
byit-myth-core/myth-admin-core/src/main/java/com/byit/conf/MythJobScheduler.java
View file @
8c195b02
...
@@ -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
();
}
}
}
}
byit-myth-core/myth-admin-core/src/main/java/com/byit/thread/JobScheduleHelper.java
View file @
8c195b02
...
@@ -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
)
{
...
...
byit-myth-core/myth-admin-core/src/main/java/com/byit/thread/LogScanHelper.java
View file @
8c195b02
...
@@ -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,37 +219,22 @@ public class LogScanHelper {
...
@@ -184,37 +219,22 @@ public class LogScanHelper {
}
catch
(
Exception
e
){
}
catch
(
Exception
e
){
e
.
printStackTrace
();
e
.
printStackTrace
();
}
finally
{
}
finally
{
freedResource
(
conn
,
preparedStatement
,
connAutoCommit
,
notAlarmedNodeScanIsStop
);
}
}
});
notAlarmedNodeScanThread
.
setName
(
"myth-job#【LogScanHelper】#notAlarmedNodeScanThread"
);
notAlarmedNodeScanThread
.
setDaemon
(
true
);
notAlarmedNodeScanThread
.
start
();
}
/**
* 释放资源
* @param conn 数据库链接
* @param preparedStatement 执行器
* @param connAutoCommit 原来的提交状态
*/
private
void
freedResource
(
Connection
conn
,
PreparedStatement
preparedStatement
,
boolean
connAutoCommit
,
boolean
isStop
){
if
(
conn
!=
null
){
if
(
conn
!=
null
){
try
{
try
{
conn
.
commit
();
conn
.
commit
();
}
catch
(
SQLException
e
)
{
}
catch
(
SQLException
e
)
{
if
(!
i
sStop
){
if
(!
notAlarmedNodeScanI
sStop
){
log
.
error
(
"--------------------【提交行锁出错】---------------------"
);
log
.
error
(
"--------------------【提交行锁出错】---------------------"
);
}
}
}
}
}
}
try
{
try
{
assert
conn
!=
null
;
if
(
conn
!=
null
){
conn
.
setAutoCommit
(
connAutoCommit
);
conn
.
setAutoCommit
(
connAutoCommit
);
}
}
catch
(
SQLException
e
)
{
}
catch
(
SQLException
e
)
{
if
(!
i
sStop
){
if
(!
notAlarmedNodeScanI
sStop
){
log
.
error
(
"--------------------【恢复自动提交出错】---------------------"
);
log
.
error
(
"--------------------【恢复自动提交出错】---------------------"
);
}
}
}
}
...
@@ -223,7 +243,7 @@ public class LogScanHelper {
...
@@ -223,7 +243,7 @@ public class LogScanHelper {
try
{
try
{
preparedStatement
.
close
();
preparedStatement
.
close
();
}
catch
(
SQLException
e
)
{
}
catch
(
SQLException
e
)
{
if
(!
i
sStop
){
if
(!
notAlarmedNodeScanI
sStop
){
log
.
error
(
"--------------------【关闭执行器出错】---------------------"
);
log
.
error
(
"--------------------【关闭执行器出错】---------------------"
);
}
}
}
}
...
@@ -232,12 +252,18 @@ public class LogScanHelper {
...
@@ -232,12 +252,18 @@ public class LogScanHelper {
try
{
try
{
conn
.
close
();
conn
.
close
();
}
catch
(
SQLException
e
)
{
}
catch
(
SQLException
e
)
{
if
(!
i
sStop
){
if
(!
notAlarmedNodeScanI
sStop
){
log
.
error
(
"--------------------【关闭链接出错】---------------------"
);
log
.
error
(
"--------------------【关闭链接出错】---------------------"
);
}
}
}
}
}
}
}
});
notAlarmedNodeScanThread
.
setName
(
"myth-job#【LogScanHelper】#notAlarmedNodeScanThread"
);
notAlarmedNodeScanThread
.
setDaemon
(
true
);
notAlarmedNodeScanThread
.
start
();
}
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
(
"---------------【日志扫描线程被注销】-----------------------"
);
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment