Commit b126d2db by huangfusuper

线程创建帮助器修改

parent e445a98e
......@@ -2,9 +2,6 @@ package com.byit.factory;
import com.byit.thread.BaseThreadRunHelper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import javax.sql.DataSource;
import java.sql.Connection;
......@@ -29,11 +26,15 @@ public class DaemonScanThreadRunHelper {
/**
* 初始睡眠时间
*/
private static final Long INIT_SLEEP_DATE = 5000L;
private static final Long INIT_SLEEP_DATE = 10000L;
/**
* 关闭等待时间
*/
private static final Long CLOSE_WAIT_TIME = 1000L;
/**
* 循环间隔
*/
private static final Long CYCLE_INTERVAL = 1000L;
/**
* 线程运行必须原料
......@@ -96,10 +97,9 @@ public class DaemonScanThreadRunHelper {
* 线程构建
* @param lockName 行锁名称
* @param examplesValue 线程运行资源
* @return
*/
private static void buildThread(String lockName, BaseThreadRunHelper examplesValue){
log.info("-----------开始构建扫描线程----------------");
log.info("-----------开始构建扫描线程,线程锁为{}----------------",lockName);
DataSource dataSource = examplesValue.getDataSource();
if(dataSource != null){
String threadClassName = examplesValue.getClass().getSimpleName();
......@@ -109,8 +109,9 @@ public class DaemonScanThreadRunHelper {
dateAligned(INIT_SLEEP_DATE,threadName);
log.info("---------------{}线程启动成功----------------",threadName);
while (!THREAD_GROUP_STOP){
dateAligned(CYCLE_INTERVAL,threadName);
//定义睡眠变量
boolean isSleep = false;
Long sleepTime = 0L;
Connection conn = null;
Boolean connAutoCommit = null;
PreparedStatement preparedStatement = null;
......@@ -124,7 +125,7 @@ public class DaemonScanThreadRunHelper {
preparedStatement = conn.prepareStatement("SELECT * FROM JOB_LOCK WHERE LOCK_NAME = '"+lockName+"' FOR UPDATE ");
preparedStatement.execute();
//调用业务操作
isSleep = examplesValue.start();
sleepTime = examplesValue.start();
}catch (Exception e){
if(!THREAD_GROUP_STOP){
e.printStackTrace();
......@@ -133,49 +134,47 @@ public class DaemonScanThreadRunHelper {
}finally {
//提交行锁
if (conn != null) {
try{
try {
conn.commit();
}catch (Exception e){
if(!THREAD_GROUP_STOP){
} catch (Exception e) {
if (!THREAD_GROUP_STOP) {
log.error("--------------------【提交行锁出错】---------------------");
}
}
}
//恢复自动提交
if (conn != null) {
try{
try {
conn.setAutoCommit(connAutoCommit);
}catch (Exception e){
if(!THREAD_GROUP_STOP){
} catch (Exception e) {
if (!THREAD_GROUP_STOP) {
log.error("--------------------【恢复自动提交出错】---------------------");
}
}
}
//关闭数据库执行器
if(preparedStatement != null){
if (preparedStatement != null) {
try {
preparedStatement.close();
} catch (SQLException e) {
if(!THREAD_GROUP_STOP){
if (!THREAD_GROUP_STOP) {
log.error("--------------------【关闭执行器出错】---------------------");
}
}
}
//关闭数据库连接
if(conn != null){
if (conn != null) {
try {
conn.close();
} catch (SQLException e) {
if(!THREAD_GROUP_STOP){
if (!THREAD_GROUP_STOP) {
log.error("--------------------【关闭执行器出错】---------------------");
}
}
}
}
if(isSleep){
dateAligned(examplesValue.getSleepTime(),threadName);
}
sleepTime = sleepTime==null?examplesValue.UNIVERSAL_WAIT_TIME:sleepTime;
dateAligned(sleepTime,threadName);
}
});
......
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