rev 优化线程相关
This commit is contained in:
@@ -3,6 +3,7 @@ package org.nl;
|
|||||||
import cn.dev33.satoken.annotation.SaIgnore;
|
import cn.dev33.satoken.annotation.SaIgnore;
|
||||||
import com.alicp.jetcache.anno.config.EnableCreateCacheAnnotation;
|
import com.alicp.jetcache.anno.config.EnableCreateCacheAnnotation;
|
||||||
import com.alicp.jetcache.anno.config.EnableMethodCache;
|
import com.alicp.jetcache.anno.config.EnableMethodCache;
|
||||||
|
import org.dromara.dynamictp.core.spring.EnableDynamicTp;
|
||||||
import org.mybatis.spring.annotation.MapperScan;
|
import org.mybatis.spring.annotation.MapperScan;
|
||||||
import org.nl.config.SpringContextHolder;
|
import org.nl.config.SpringContextHolder;
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
@@ -24,6 +25,7 @@ import org.springframework.web.bind.annotation.RestController;
|
|||||||
*/
|
*/
|
||||||
@EnableAsync
|
@EnableAsync
|
||||||
@RestController
|
@RestController
|
||||||
|
@EnableDynamicTp
|
||||||
@SpringBootApplication(exclude = {
|
@SpringBootApplication(exclude = {
|
||||||
QuartzAutoConfiguration.class,
|
QuartzAutoConfiguration.class,
|
||||||
org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration.class
|
org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration.class
|
||||||
@@ -33,6 +35,7 @@ import org.springframework.web.bind.annotation.RestController;
|
|||||||
@EnableMethodCache(basePackages = "org.nl")
|
@EnableMethodCache(basePackages = "org.nl")
|
||||||
@EnableCreateCacheAnnotation
|
@EnableCreateCacheAnnotation
|
||||||
@MapperScan("org.nl.**.mapper")
|
@MapperScan("org.nl.**.mapper")
|
||||||
|
|
||||||
public class AppRun {
|
public class AppRun {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|||||||
@@ -69,7 +69,6 @@ public class AgvNdcTwoDeviceDriver extends AbstractDeviceDriver implements Devic
|
|||||||
DeviceErrorLogService deviceErrorLogService = SpringContextHolder.getBean(DeviceErrorLogServiceImpl.class);
|
DeviceErrorLogService deviceErrorLogService = SpringContextHolder.getBean(DeviceErrorLogServiceImpl.class);
|
||||||
DeviceService deviceService = SpringContextHolder.getBean(DeviceService.class);
|
DeviceService deviceService = SpringContextHolder.getBean(DeviceService.class);
|
||||||
LuceneExecuteLogService luceneExecuteLogService = SpringContextHolder.getBean(LuceneExecuteLogService.class);
|
LuceneExecuteLogService luceneExecuteLogService = SpringContextHolder.getBean(LuceneExecuteLogService.class);
|
||||||
final ThreadPoolExecutor EXECUTOR = ThreadPoolExecutorUtil.getPoll();
|
|
||||||
TwoAgvPhase twoAgvPhase = new TwoAgvPhase();
|
TwoAgvPhase twoAgvPhase = new TwoAgvPhase();
|
||||||
|
|
||||||
String error_code = "0";
|
String error_code = "0";
|
||||||
|
|||||||
@@ -45,7 +45,6 @@ import org.nl.config.thread.ThreadPoolExecutorUtil;
|
|||||||
import org.openscada.opc.lib.da.Server;
|
import org.openscada.opc.lib.da.Server;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.ThreadPoolExecutor;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 一楼木箱入库站点
|
* 一楼木箱入库站点
|
||||||
@@ -54,7 +53,6 @@ import java.util.concurrent.ThreadPoolExecutor;
|
|||||||
@Data
|
@Data
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class BoxStorageOutConveyorDeviceDriver extends AbstractOpcDeviceDriver implements DeviceDriver, ExecutableDeviceDriver, RouteableDeviceDriver, DeviceStageMonitor, FeedLmsRealFailed {
|
public class BoxStorageOutConveyorDeviceDriver extends AbstractOpcDeviceDriver implements DeviceDriver, ExecutableDeviceDriver, RouteableDeviceDriver, DeviceStageMonitor, FeedLmsRealFailed {
|
||||||
private final static ThreadPoolExecutor EXECUTOR = ThreadPoolExecutorUtil.getPoll();
|
|
||||||
protected ItemProtocol itemProtocol = new ItemProtocol(this);
|
protected ItemProtocol itemProtocol = new ItemProtocol(this);
|
||||||
InstructionService instructionService = SpringContextHolder.getBean(InstructionService.class);
|
InstructionService instructionService = SpringContextHolder.getBean(InstructionService.class);
|
||||||
|
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ import org.nl.system.service.param.ISysParamService;
|
|||||||
import org.openscada.opc.lib.da.Server;
|
import org.openscada.opc.lib.da.Server;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.concurrent.Executor;
|
||||||
import java.util.concurrent.ThreadPoolExecutor;
|
import java.util.concurrent.ThreadPoolExecutor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -53,7 +54,7 @@ import java.util.concurrent.ThreadPoolExecutor;
|
|||||||
@Data
|
@Data
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class BoxSubvolumesConveyorDeviceDriver extends AbstractOpcDeviceDriver implements DeviceDriver, ExecutableDeviceDriver, RouteableDeviceDriver, DeviceStageMonitor, FeedLmsRealFailed {
|
public class BoxSubvolumesConveyorDeviceDriver extends AbstractOpcDeviceDriver implements DeviceDriver, ExecutableDeviceDriver, RouteableDeviceDriver, DeviceStageMonitor, FeedLmsRealFailed {
|
||||||
private final static ThreadPoolExecutor EXECUTOR = ThreadPoolExecutorUtil.getPoll();
|
private final static Executor EXECUTOR = ThreadPoolExecutorUtil.getPoll();
|
||||||
protected ItemProtocol itemProtocol = new ItemProtocol(this);
|
protected ItemProtocol itemProtocol = new ItemProtocol(this);
|
||||||
InstructionService instructionService = SpringContextHolder.getBean(InstructionService.class);
|
InstructionService instructionService = SpringContextHolder.getBean(InstructionService.class);
|
||||||
|
|
||||||
|
|||||||
@@ -53,7 +53,6 @@ import java.util.concurrent.ThreadPoolExecutor;
|
|||||||
@Data
|
@Data
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class FinishedProductOutBindLableDeviceDriver extends AbstractOpcDeviceDriver implements DeviceDriver, ExecutableDeviceDriver, RouteableDeviceDriver, DeviceStageMonitor, FeedLmsRealFailed {
|
public class FinishedProductOutBindLableDeviceDriver extends AbstractOpcDeviceDriver implements DeviceDriver, ExecutableDeviceDriver, RouteableDeviceDriver, DeviceStageMonitor, FeedLmsRealFailed {
|
||||||
private final static ThreadPoolExecutor EXECUTOR = ThreadPoolExecutorUtil.getPoll();
|
|
||||||
protected ItemProtocol itemProtocol = new ItemProtocol(this);
|
protected ItemProtocol itemProtocol = new ItemProtocol(this);
|
||||||
InstructionService instructionService = SpringContextHolder.getBean(InstructionService.class);
|
InstructionService instructionService = SpringContextHolder.getBean(InstructionService.class);
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ import java.util.concurrent.ThreadPoolExecutor;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
@Data
|
@Data
|
||||||
public class ManipulatorCacheDeviceDriver extends AbstractOpcDeviceDriver implements DeviceDriver, ExecutableDeviceDriver, RouteableDeviceDriver, DeviceStageMonitor, FeedLmsRealFailed {
|
public class ManipulatorCacheDeviceDriver extends AbstractOpcDeviceDriver implements DeviceDriver, ExecutableDeviceDriver, RouteableDeviceDriver, DeviceStageMonitor, FeedLmsRealFailed {
|
||||||
private final static ThreadPoolExecutor EXECUTOR = ThreadPoolExecutorUtil.getPoll();
|
|
||||||
protected ItemProtocol itemProtocol = new ItemProtocol(this);
|
protected ItemProtocol itemProtocol = new ItemProtocol(this);
|
||||||
|
|
||||||
//当前指令
|
//当前指令
|
||||||
|
|||||||
@@ -51,7 +51,6 @@ import java.util.concurrent.ThreadPoolExecutor;
|
|||||||
@Data
|
@Data
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class UnBoxLableConveyorDeviceDriver extends AbstractOpcDeviceDriver implements DeviceDriver, ExecutableDeviceDriver, RouteableDeviceDriver, DeviceStageMonitor, FeedLmsRealFailed {
|
public class UnBoxLableConveyorDeviceDriver extends AbstractOpcDeviceDriver implements DeviceDriver, ExecutableDeviceDriver, RouteableDeviceDriver, DeviceStageMonitor, FeedLmsRealFailed {
|
||||||
private final static ThreadPoolExecutor EXECUTOR = ThreadPoolExecutorUtil.getPoll();
|
|
||||||
protected ItemProtocol itemProtocol = new ItemProtocol(this);
|
protected ItemProtocol itemProtocol = new ItemProtocol(this);
|
||||||
InstructionService instructionService = SpringContextHolder.getBean(InstructionService.class);
|
InstructionService instructionService = SpringContextHolder.getBean(InstructionService.class);
|
||||||
|
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ import org.nl.config.thread.ThreadPoolExecutorUtil;
|
|||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.ThreadPoolExecutor;
|
import java.util.concurrent.Executor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 烘箱-行架机械手
|
* 烘箱-行架机械手
|
||||||
@@ -79,7 +79,7 @@ public class OvenGantryManipulatorDeviceDriver extends AbstractOpcDeviceDriver i
|
|||||||
@Autowired
|
@Autowired
|
||||||
LuceneExecuteLogService luceneExecuteLogService = SpringContextHolder.getBean(LuceneExecuteLogService.class);
|
LuceneExecuteLogService luceneExecuteLogService = SpringContextHolder.getBean(LuceneExecuteLogService.class);
|
||||||
|
|
||||||
final ThreadPoolExecutor EXECUTOR = ThreadPoolExecutorUtil.getPoll();
|
final Executor EXECUTOR = ThreadPoolExecutorUtil.getPoll();
|
||||||
|
|
||||||
//工作模式
|
//工作模式
|
||||||
int mode = 0;
|
int mode = 0;
|
||||||
@@ -464,12 +464,12 @@ public class OvenGantryManipulatorDeviceDriver extends AbstractOpcDeviceDriver i
|
|||||||
list.add(map3);
|
list.add(map3);
|
||||||
this.writing(list);
|
this.writing(list);
|
||||||
if (startdevice.getDeviceDriver() instanceof HongXiangConveyorDeviceDriver) {
|
if (startdevice.getDeviceDriver() instanceof HongXiangConveyorDeviceDriver) {
|
||||||
EXECUTOR.submit(() -> {
|
EXECUTOR.execute(() -> {
|
||||||
toOpenDoor(startdevice);
|
toOpenDoor(startdevice);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (nextdevice.getDeviceDriver() instanceof HongXiangConveyorDeviceDriver) {
|
if (nextdevice.getDeviceDriver() instanceof HongXiangConveyorDeviceDriver) {
|
||||||
EXECUTOR.submit(() -> {
|
EXECUTOR.execute(() -> {
|
||||||
toOpenDoor(nextdevice);
|
toOpenDoor(nextdevice);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -672,12 +672,12 @@ public class OvenGantryManipulatorDeviceDriver extends AbstractOpcDeviceDriver i
|
|||||||
list.add(map3);
|
list.add(map3);
|
||||||
this.writing(list);
|
this.writing(list);
|
||||||
if (startdevice.getDeviceDriver() instanceof HongXiangConveyorDeviceDriver) {
|
if (startdevice.getDeviceDriver() instanceof HongXiangConveyorDeviceDriver) {
|
||||||
EXECUTOR.submit(() -> {
|
EXECUTOR.execute(() -> {
|
||||||
toOpenDoor(startdevice);
|
toOpenDoor(startdevice);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (nextdevice.getDeviceDriver() instanceof HongXiangConveyorDeviceDriver) {
|
if (nextdevice.getDeviceDriver() instanceof HongXiangConveyorDeviceDriver) {
|
||||||
EXECUTOR.submit(() -> {
|
EXECUTOR.execute(() -> {
|
||||||
toOpenDoor(nextdevice);
|
toOpenDoor(nextdevice);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -938,7 +938,7 @@ public class OvenGantryManipulatorDeviceDriver extends AbstractOpcDeviceDriver i
|
|||||||
HongXiangConveyorDeviceDriver hongXiangConveyorDeviceDriver;
|
HongXiangConveyorDeviceDriver hongXiangConveyorDeviceDriver;
|
||||||
if (device.getDeviceDriver() instanceof HongXiangConveyorDeviceDriver) {
|
if (device.getDeviceDriver() instanceof HongXiangConveyorDeviceDriver) {
|
||||||
hongXiangConveyorDeviceDriver = (HongXiangConveyorDeviceDriver) device.getDeviceDriver();
|
hongXiangConveyorDeviceDriver = (HongXiangConveyorDeviceDriver) device.getDeviceDriver();
|
||||||
EXECUTOR.submit(() -> {
|
EXECUTOR.execute(() -> {
|
||||||
toCloseDoor(device);
|
toCloseDoor(device);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -1040,7 +1040,7 @@ public class OvenGantryManipulatorDeviceDriver extends AbstractOpcDeviceDriver i
|
|||||||
LampThreecolorDeviceDriver lampThreecolorDeviceDriver;
|
LampThreecolorDeviceDriver lampThreecolorDeviceDriver;
|
||||||
if (nextDevice.getDeviceDriver() instanceof HongXiangConveyorDeviceDriver) {
|
if (nextDevice.getDeviceDriver() instanceof HongXiangConveyorDeviceDriver) {
|
||||||
hongXiangConveyorDeviceDriver = (HongXiangConveyorDeviceDriver) nextDevice.getDeviceDriver();
|
hongXiangConveyorDeviceDriver = (HongXiangConveyorDeviceDriver) nextDevice.getDeviceDriver();
|
||||||
EXECUTOR.submit(() -> {
|
EXECUTOR.execute(() -> {
|
||||||
toCloseDoor(nextDevice);
|
toCloseDoor(nextDevice);
|
||||||
});
|
});
|
||||||
if (StrUtil.isNotEmpty(taskDto.getOven_time())) {
|
if (StrUtil.isNotEmpty(taskDto.getOven_time())) {
|
||||||
|
|||||||
@@ -7,9 +7,12 @@ import org.nl.acs.device_driver.driver.ExecutableDeviceDriver;
|
|||||||
import org.nl.acs.udw.UnifiedDataAccessor;
|
import org.nl.acs.udw.UnifiedDataAccessor;
|
||||||
import org.nl.acs.udw.UnifiedDataAccessorFactory;
|
import org.nl.acs.udw.UnifiedDataAccessorFactory;
|
||||||
import org.nl.config.thread.TheadFactoryName;
|
import org.nl.config.thread.TheadFactoryName;
|
||||||
|
import org.nl.config.thread.ThreadPoolExecutorUtil;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.core.annotation.Order;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.*;
|
import java.util.concurrent.*;
|
||||||
@@ -30,7 +33,10 @@ public class DeviceExecuteAutoRun extends AbstractAutoRunnable {
|
|||||||
int multiple = cache_thread;
|
int multiple = cache_thread;
|
||||||
|
|
||||||
int loop_time_millions = 100;
|
int loop_time_millions = 100;
|
||||||
ExecutorService executorService;
|
|
||||||
|
@Resource
|
||||||
|
private ThreadPoolExecutor executorService;
|
||||||
|
|
||||||
Map<String, BlockedRunable> runs;
|
Map<String, BlockedRunable> runs;
|
||||||
|
|
||||||
public DeviceExecuteAutoRun() {
|
public DeviceExecuteAutoRun() {
|
||||||
@@ -43,7 +49,7 @@ public class DeviceExecuteAutoRun extends AbstractAutoRunnable {
|
|||||||
new ArrayBlockingQueue<>( queueLength),
|
new ArrayBlockingQueue<>( queueLength),
|
||||||
new TheadFactoryName()
|
new TheadFactoryName()
|
||||||
);*/
|
);*/
|
||||||
this.executorService = new ThreadPoolExecutor(
|
/*this.executorService = new ThreadPoolExecutor(
|
||||||
50,
|
50,
|
||||||
100,
|
100,
|
||||||
1L,
|
1L,
|
||||||
@@ -62,7 +68,8 @@ public class DeviceExecuteAutoRun extends AbstractAutoRunnable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);*/
|
||||||
|
// this.executorService= ThreadPoolExecutorUtil.getPoll();
|
||||||
this.runs = new LinkedHashMap();
|
this.runs = new LinkedHashMap();
|
||||||
this.runs = Collections.synchronizedMap(this.runs);
|
this.runs = Collections.synchronizedMap(this.runs);
|
||||||
}
|
}
|
||||||
@@ -121,7 +128,7 @@ public class DeviceExecuteAutoRun extends AbstractAutoRunnable {
|
|||||||
this.runs.put(deviceDriver.getDeviceCode(), runnable);
|
this.runs.put(deviceDriver.getDeviceCode(), runnable);
|
||||||
}
|
}
|
||||||
runnable.setIndex(this.runs);
|
runnable.setIndex(this.runs);
|
||||||
this.executorService.submit(runnable);
|
this.executorService.execute(runnable);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,18 +1,24 @@
|
|||||||
package org.nl.acs.opc;
|
package org.nl.acs.opc;
|
||||||
|
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
|
import org.dromara.dynamictp.core.support.ThreadPoolBuilder;
|
||||||
import org.nl.acs.auto.run.AbstractAutoRunnable;
|
import org.nl.acs.auto.run.AbstractAutoRunnable;
|
||||||
import org.nl.acs.opc.service.dto.OpcServerManageDto;
|
import org.nl.acs.opc.service.dto.OpcServerManageDto;
|
||||||
import org.nl.config.thread.TheadFactoryName;
|
import org.nl.config.thread.TheadFactoryName;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
|
import java.util.concurrent.ThreadPoolExecutor;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import static org.dromara.dynamictp.common.em.QueueTypeEnum.MEMORY_SAFE_LINKED_BLOCKING_QUEUE;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* OPC设备同步启动
|
* OPC设备同步启动
|
||||||
@@ -22,7 +28,16 @@ import java.util.concurrent.Executors;
|
|||||||
public class DeviceOpcSynchronizeAutoRun extends AbstractAutoRunnable {
|
public class DeviceOpcSynchronizeAutoRun extends AbstractAutoRunnable {
|
||||||
|
|
||||||
public static boolean isRun = false;
|
public static boolean isRun = false;
|
||||||
ExecutorService executorService = Executors.newCachedThreadPool();
|
ExecutorService executorService = ThreadPoolBuilder.newBuilder()
|
||||||
|
.threadPoolName("deviceOpc_thread")
|
||||||
|
.threadFactory("deviceOpc_thread")
|
||||||
|
.corePoolSize(2)
|
||||||
|
.maximumPoolSize(7)
|
||||||
|
.keepAliveTime(40)
|
||||||
|
.timeUnit(TimeUnit.SECONDS)
|
||||||
|
.workQueue(MEMORY_SAFE_LINKED_BLOCKING_QUEUE.getName(), 2000)
|
||||||
|
.buildDynamic();
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private DeviceAppService deviceAppService;
|
private DeviceAppService deviceAppService;
|
||||||
@Autowired
|
@Autowired
|
||||||
@@ -80,6 +95,14 @@ public class DeviceOpcSynchronizeAutoRun extends AbstractAutoRunnable {
|
|||||||
public void after() {
|
public void after() {
|
||||||
isRun = false;
|
isRun = false;
|
||||||
this.executorService.shutdownNow();
|
this.executorService.shutdownNow();
|
||||||
this.executorService = Executors.newCachedThreadPool();
|
this.executorService = ThreadPoolBuilder.newBuilder()
|
||||||
|
.threadPoolName("deviceOpc_thread")
|
||||||
|
.threadFactory("deviceOpc_thread")
|
||||||
|
.corePoolSize(2)
|
||||||
|
.maximumPoolSize(7)
|
||||||
|
.keepAliveTime(40)
|
||||||
|
.timeUnit(TimeUnit.SECONDS)
|
||||||
|
.workQueue(MEMORY_SAFE_LINKED_BLOCKING_QUEUE.getName(), 2000)
|
||||||
|
.buildDynamic();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package org.nl.acs.socket;
|
package org.nl.acs.socket;
|
||||||
|
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import org.dromara.dynamictp.core.support.ThreadPoolBuilder;
|
||||||
import org.nl.acs.auto.run.AbstractAutoRunnable;
|
import org.nl.acs.auto.run.AbstractAutoRunnable;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@@ -14,6 +15,9 @@ import java.util.HashMap;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import static org.dromara.dynamictp.common.em.QueueTypeEnum.MEMORY_SAFE_LINKED_BLOCKING_QUEUE;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author 20220102CG\noblelift
|
* @author 20220102CG\noblelift
|
||||||
@@ -22,7 +26,15 @@ import java.util.concurrent.Executors;
|
|||||||
public class SocketListenerAutoRun extends AbstractAutoRunnable implements SocketService {
|
public class SocketListenerAutoRun extends AbstractAutoRunnable implements SocketService {
|
||||||
private static final Logger log = LoggerFactory.getLogger(SocketListenerAutoRun.class);
|
private static final Logger log = LoggerFactory.getLogger(SocketListenerAutoRun.class);
|
||||||
private ServerSocket serverSocket = null;
|
private ServerSocket serverSocket = null;
|
||||||
private ExecutorService threadPool = Executors.newCachedThreadPool();
|
private ExecutorService threadPool = ThreadPoolBuilder.newBuilder()
|
||||||
|
.threadPoolName("socketListener_thread")
|
||||||
|
.threadFactory("socketListener_thread")
|
||||||
|
.corePoolSize(2)
|
||||||
|
.maximumPoolSize(7)
|
||||||
|
.keepAliveTime(40)
|
||||||
|
.timeUnit(TimeUnit.SECONDS)
|
||||||
|
.workQueue(MEMORY_SAFE_LINKED_BLOCKING_QUEUE.getName(), 2000)
|
||||||
|
.buildDynamic();
|
||||||
private Map<String, Socket> sockets = new HashMap();
|
private Map<String, Socket> sockets = new HashMap();
|
||||||
private Map<String, OutputStream> outputs = new HashMap();
|
private Map<String, OutputStream> outputs = new HashMap();
|
||||||
|
|
||||||
@@ -91,7 +103,15 @@ public class SocketListenerAutoRun extends AbstractAutoRunnable implements Socke
|
|||||||
public void after() {
|
public void after() {
|
||||||
System.out.println("清理工作。。。。。");
|
System.out.println("清理工作。。。。。");
|
||||||
this.threadPool.shutdownNow();
|
this.threadPool.shutdownNow();
|
||||||
this.threadPool = Executors.newCachedThreadPool();
|
this.threadPool = ThreadPoolBuilder.newBuilder()
|
||||||
|
.threadPoolName("socketListener_thread")
|
||||||
|
.threadFactory("socketListener_thread")
|
||||||
|
.corePoolSize(2)
|
||||||
|
.maximumPoolSize(7)
|
||||||
|
.keepAliveTime(40)
|
||||||
|
.timeUnit(TimeUnit.SECONDS)
|
||||||
|
.workQueue(MEMORY_SAFE_LINKED_BLOCKING_QUEUE.getName(), 2000)
|
||||||
|
.buildDynamic();
|
||||||
this.sockets = new HashMap();
|
this.sockets = new HashMap();
|
||||||
this.outputs = new HashMap();
|
this.outputs = new HashMap();
|
||||||
this.closeSocket(this.serverSocket);
|
this.closeSocket(this.serverSocket);
|
||||||
|
|||||||
@@ -16,10 +16,12 @@
|
|||||||
package org.nl.config.thread;
|
package org.nl.config.thread;
|
||||||
|
|
||||||
|
|
||||||
|
import org.dromara.dynamictp.core.DtpRegistry;
|
||||||
import org.nl.config.SpringContextHolder;
|
import org.nl.config.SpringContextHolder;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.util.concurrent.ArrayBlockingQueue;
|
import java.util.concurrent.ArrayBlockingQueue;
|
||||||
|
import java.util.concurrent.Executor;
|
||||||
import java.util.concurrent.ThreadPoolExecutor;
|
import java.util.concurrent.ThreadPoolExecutor;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
@@ -31,8 +33,11 @@ import java.util.concurrent.TimeUnit;
|
|||||||
public class ThreadPoolExecutorUtil {
|
public class ThreadPoolExecutorUtil {
|
||||||
|
|
||||||
|
|
||||||
public static ThreadPoolExecutor getPoll(){
|
public static Executor getPoll(){
|
||||||
AsyncTaskProperties properties = SpringContextHolder.getBean(AsyncTaskProperties.class);
|
|
||||||
|
return DtpRegistry.getExecutor("dtpExecutor1");
|
||||||
|
|
||||||
|
/* AsyncTaskProperties properties = SpringContextHolder.getBean(AsyncTaskProperties.class);
|
||||||
return new ThreadPoolExecutor(
|
return new ThreadPoolExecutor(
|
||||||
properties.getCorePoolSize(),
|
properties.getCorePoolSize(),
|
||||||
properties.getMaxPoolSize(),
|
properties.getMaxPoolSize(),
|
||||||
@@ -40,6 +45,6 @@ public class ThreadPoolExecutorUtil {
|
|||||||
TimeUnit.SECONDS,
|
TimeUnit.SECONDS,
|
||||||
new ArrayBlockingQueue<>(properties.getQueueCapacity()),
|
new ArrayBlockingQueue<>(properties.getQueueCapacity()),
|
||||||
new TheadFactoryName()
|
new TheadFactoryName()
|
||||||
);
|
);*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ import lombok.extern.slf4j.Slf4j;
|
|||||||
import org.nl.common.utils.RedisUtils;
|
import org.nl.common.utils.RedisUtils;
|
||||||
import org.nl.common.utils.ThrowableUtil;
|
import org.nl.common.utils.ThrowableUtil;
|
||||||
import org.nl.config.SpringContextHolder;
|
import org.nl.config.SpringContextHolder;
|
||||||
|
import org.nl.config.thread.AsyncTaskProperties;
|
||||||
|
import org.nl.config.thread.TheadFactoryName;
|
||||||
import org.nl.config.thread.ThreadPoolExecutorUtil;
|
import org.nl.config.thread.ThreadPoolExecutorUtil;
|
||||||
import org.nl.system.service.quartz.ISysQuartzJobService;
|
import org.nl.system.service.quartz.ISysQuartzJobService;
|
||||||
import org.nl.system.service.quartz.dao.SysQuartzJob;
|
import org.nl.system.service.quartz.dao.SysQuartzJob;
|
||||||
@@ -21,8 +23,10 @@ import org.springframework.beans.factory.annotation.Qualifier;
|
|||||||
import org.springframework.scheduling.annotation.Async;
|
import org.springframework.scheduling.annotation.Async;
|
||||||
import org.springframework.scheduling.quartz.QuartzJobBean;
|
import org.springframework.scheduling.quartz.QuartzJobBean;
|
||||||
|
|
||||||
|
import java.util.concurrent.ArrayBlockingQueue;
|
||||||
import java.util.concurrent.Future;
|
import java.util.concurrent.Future;
|
||||||
import java.util.concurrent.ThreadPoolExecutor;
|
import java.util.concurrent.ThreadPoolExecutor;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Author: /
|
* @Author: /
|
||||||
@@ -41,8 +45,16 @@ public class ExecutionJob extends TLogQuartzJobBean {
|
|||||||
/* @Autowired
|
/* @Autowired
|
||||||
@Qualifier("threadPoolExecutor")
|
@Qualifier("threadPoolExecutor")
|
||||||
private ThreadPoolExecutor EXECUTOR;*/
|
private ThreadPoolExecutor EXECUTOR;*/
|
||||||
|
static AsyncTaskProperties properties = SpringContextHolder.getBean(AsyncTaskProperties.class);
|
||||||
|
|
||||||
private final static ThreadPoolExecutor EXECUTOR = ThreadPoolExecutorUtil.getPoll();
|
private final static ThreadPoolExecutor EXECUTOR = new ThreadPoolExecutor(
|
||||||
|
properties.getCorePoolSize(),
|
||||||
|
properties.getMaxPoolSize(),
|
||||||
|
properties.getKeepAliveSeconds(),
|
||||||
|
TimeUnit.SECONDS,
|
||||||
|
new ArrayBlockingQueue<>(properties.getQueueCapacity()),
|
||||||
|
new TheadFactoryName()
|
||||||
|
);;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ spring:
|
|||||||
check-template-location: false
|
check-template-location: false
|
||||||
profiles:
|
profiles:
|
||||||
active: dev
|
active: dev
|
||||||
# active: prod
|
|
||||||
jackson:
|
jackson:
|
||||||
time-zone: GMT+8
|
time-zone: GMT+8
|
||||||
data:
|
data:
|
||||||
@@ -44,7 +43,7 @@ spring:
|
|||||||
enable_lazy_load_no_trans: true
|
enable_lazy_load_no_trans: true
|
||||||
dynamic:
|
dynamic:
|
||||||
tp:
|
tp:
|
||||||
enabled: false # 是否启用 dynamictp,默认true
|
enabled: true # 是否启用 dynamictp,默认true
|
||||||
enabledBanner: false # 是否启用 控制台banner,默认true
|
enabledBanner: false # 是否启用 控制台banner,默认true
|
||||||
enabledCollect: true # 是否开启监控指标采集,默认true
|
enabledCollect: true # 是否开启监控指标采集,默认true
|
||||||
collectorTypes: logging,test_collect # 监控数据采集器类型(logging | micrometer | internal_logging),默认micrometer
|
collectorTypes: logging,test_collect # 监控数据采集器类型(logging | micrometer | internal_logging),默认micrometer
|
||||||
@@ -57,30 +56,23 @@ spring:
|
|||||||
keepAliveTime: 60
|
keepAliveTime: 60
|
||||||
runTimeout: 10000
|
runTimeout: 10000
|
||||||
queueTimeout: 100
|
queueTimeout: 100
|
||||||
notifyItems: # 报警项,不配置自动会按默认值配置(变更通知、容量报警、活性报警、拒绝报警、任务超时报警)
|
executors: # 动态线程池配置,都有默认值,采用默认值的可以不配置该项,减少配置量
|
||||||
- type: change
|
- threadPoolName: dtpExecutor1 # 线程池名称,必填
|
||||||
enabled: true
|
threadPoolAliasName: core_thread # 线程池别名,可选
|
||||||
|
executorType: common # 线程池类型 common、eager、ordered、scheduled、priority,默认 common
|
||||||
- type: capacity # 队列容量使用率,报警项类型,查看源码 NotifyTypeEnum枚举类
|
corePoolSize: 10 # 核心线程数,默认1
|
||||||
enabled: true
|
maximumPoolSize: 30 # 最大线程数,默认cpu核数
|
||||||
threshold: 80 # 报警阈值,默认70,意思是队列使用率达到70%告警
|
queueCapacity: 1024 # 队列容量,默认1024
|
||||||
interval: 120 # 报警间隔(单位:s),默认120
|
queueType: VariableLinkedBlockingQueue # 任务队列,查看源码QueueTypeEnum枚举类,默认VariableLinkedBlockingQueue
|
||||||
|
rejectedHandlerType: CallerRunsPolicy # 拒绝策略,查看RejectedTypeEnum枚举类,默认AbortPolicy
|
||||||
- type: liveness # 线程池活性
|
keepAliveTime: 30 # 空闲线程等待超时时间,默认60
|
||||||
enabled: true
|
threadNamePrefix: core_thread # 线程名前缀,默认dtp
|
||||||
threshold: 80 # 报警阈值,默认 70,意思是活性达到70%告警
|
allowCoreThreadTimeOut: true # 是否允许核心线程池超时,默认false
|
||||||
|
waitForTasksToCompleteOnShutdown: true # 参考spring线程池设计,优雅关闭线程池,默认true
|
||||||
- type: reject # 触发任务拒绝告警
|
awaitTerminationSeconds: 5 # 优雅关闭线程池时,阻塞等待线程池中任务执行时间,默认3,单位(s)
|
||||||
enabled: true
|
preStartAllCoreThreads: false # 是否预热所有核心线程,默认false
|
||||||
threshold: 100 # 默认阈值10
|
runTimeout: 2000 # 任务执行超时阈值,单位(ms),默认0(不统计)
|
||||||
|
queueTimeout: 1000 # 任务在队列等待超时阈值,单位(ms),默认0(不统计)
|
||||||
- type: run_timeout # 任务执行超时告警
|
|
||||||
enabled: true
|
|
||||||
threshold: 100 # 默认阈值10
|
|
||||||
|
|
||||||
- type: queue_timeout # 任务排队超时告警
|
|
||||||
enabled: true
|
|
||||||
threshold: 100 # 默认阈值10
|
|
||||||
task:
|
task:
|
||||||
pool:
|
pool:
|
||||||
# 核心线程池大小
|
# 核心线程池大小
|
||||||
@@ -137,7 +129,7 @@ security:
|
|||||||
mybatis-plus:
|
mybatis-plus:
|
||||||
configuration:
|
configuration:
|
||||||
map-underscore-to-camel-case: false
|
map-underscore-to-camel-case: false
|
||||||
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
|
log-impl: org.apache.ibatis.logging.nologging.NoLoggingImpl
|
||||||
mapper-locations:
|
mapper-locations:
|
||||||
- classpath:org.nl.**.mapper/*.xml
|
- classpath:org.nl.**.mapper/*.xml
|
||||||
global-config:
|
global-config:
|
||||||
|
|||||||
@@ -69,11 +69,11 @@ https://juejin.cn/post/6844903775631572999
|
|||||||
<!--开发环境:打印控制台-->
|
<!--开发环境:打印控制台-->
|
||||||
<springProfile name="dev">
|
<springProfile name="dev">
|
||||||
<root level="debug">
|
<root level="debug">
|
||||||
<appender-ref ref="asyncLuceneAppender"/>
|
<!-- <appender-ref ref="asyncLuceneAppender"/>-->
|
||||||
<appender-ref ref="asyncFileAppender"/>
|
<!-- <appender-ref ref="asyncFileAppender"/>-->
|
||||||
<appender-ref ref="CONSOLE"/>
|
<appender-ref ref="CONSOLE"/>
|
||||||
</root>
|
</root>
|
||||||
<logger name="jdbc" level="ERROR" additivity="true">
|
<!-- <logger name="jdbc" level="ERROR" additivity="true">
|
||||||
<appender-ref ref="asyncFileAppender"/>
|
<appender-ref ref="asyncFileAppender"/>
|
||||||
</logger>
|
</logger>
|
||||||
<logger name="org.springframework" level="ERROR" additivity="true">
|
<logger name="org.springframework" level="ERROR" additivity="true">
|
||||||
@@ -96,7 +96,7 @@ https://juejin.cn/post/6844903775631572999
|
|||||||
</logger>
|
</logger>
|
||||||
<logger name="org.jinterop" level="ERROR" additivity="true">
|
<logger name="org.jinterop" level="ERROR" additivity="true">
|
||||||
<appender-ref ref="asyncFileAppender"/>
|
<appender-ref ref="asyncFileAppender"/>
|
||||||
</logger>
|
</logger>-->
|
||||||
</springProfile>
|
</springProfile>
|
||||||
|
|
||||||
<!--测试环境:打印控制台-->
|
<!--测试环境:打印控制台-->
|
||||||
|
|||||||
Reference in New Issue
Block a user