修复i2内存泄漏的bug

master
liuguijing 1 year ago
parent 82f307293f
commit fc1e415fb1

@ -20,8 +20,8 @@ import org.springframework.scheduling.annotation.EnableScheduling;
@Slf4j @Slf4j
@EnableConfigurationProperties @EnableConfigurationProperties
@ComponentScan(basePackages = {"com.shxy"}) @ComponentScan(basePackages = {"com.shxy"})
@EnableCaching //@EnableCaching
@EnableAsync //@EnableAsync
public class I2Application { public class I2Application {
public static void main(String[] args) { public static void main(String[] args) {

@ -10,8 +10,6 @@ import com.shxy.i2.dao.*;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.cxf.endpoint.Client; import org.apache.cxf.endpoint.Client;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.math.BigInteger; import java.math.BigInteger;
@ -21,7 +19,7 @@ import java.util.List;
@Slf4j @Slf4j
@Component @Component
@EnableAsync //@EnableAsync
public class AsyncMethod { public class AsyncMethod {
@Autowired @Autowired
private Data_Dlq_JbfdDao data_dlq_jbfdDao; private Data_Dlq_JbfdDao data_dlq_jbfdDao;
@ -68,8 +66,11 @@ public class AsyncMethod {
@Autowired @Autowired
private Upload_checkDao upload_checkDao; private Upload_checkDao upload_checkDao;
@Autowired
private Client createDynamicClient;
@Async(value = "asyncServiceExecutor") // @Async(value = "asyncServiceExecutor")
public void sendData(Client client, List<BigInteger> idlist, String xml, String type) throws Exception { public void sendData(Client client, List<BigInteger> idlist, String xml, String type) throws Exception {
Object[] objects = client.invoke("uploadCACData", xml); Object[] objects = client.invoke("uploadCACData", xml);
String threadId = Thread.currentThread().getName(); String threadId = Thread.currentThread().getName();
@ -129,7 +130,7 @@ public class AsyncMethod {
} }
} }
@Async(value = "asyncServiceExecutor") // @Async(value = "asyncServiceExecutor")
public void sendJBFDData2(Client client, BigInteger maxid, ArrayList<Integer> list1, String xml, String type) throws Exception { public void sendJBFDData2(Client client, BigInteger maxid, ArrayList<Integer> list1, String xml, String type) throws Exception {
Object[] objects = client.invoke("uploadCACData", xml); Object[] objects = client.invoke("uploadCACData", xml);
String threadId = Thread.currentThread().getName(); String threadId = Thread.currentThread().getName();
@ -166,9 +167,9 @@ public class AsyncMethod {
} }
} }
@Async(value = "asyncServiceExecutor") // @Async(value = "asyncServiceExecutor")
public void sendData2(Client client, String xml) throws Exception { public void sendData2(Client client, String xml) throws Exception {
Object[] objects = client.invoke("uploadCACData", xml); Object[] objects = createDynamicClient.invoke("uploadCACData", xml);
String threadId = Thread.currentThread().getName(); String threadId = Thread.currentThread().getName();
log.info("线程序号: " + threadId + "当前时间:" + new Date()); log.info("线程序号: " + threadId + "当前时间:" + new Date());
if (objects != null && objects.length > 0) { if (objects != null && objects.length > 0) {
@ -193,7 +194,7 @@ public class AsyncMethod {
} }
@Async(value = "asyncServiceExecutor") // @Async(value = "asyncServiceExecutor")
public void sendYxData(Client client, BigInteger maxid, String xml) throws Exception { public void sendYxData(Client client, BigInteger maxid, String xml) throws Exception {
// Object[] objects = client.invoke("uploadCACData", xml); // Object[] objects = client.invoke("uploadCACData", xml);
// if (objects != null && objects.length > 0) { // if (objects != null && objects.length > 0) {

@ -1,35 +1,59 @@
//package com.shxy.i2.configure; package com.shxy.i2.configure;
import lombok.extern.slf4j.Slf4j;
import org.apache.cxf.endpoint.Client;
import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory;
import org.apache.cxf.transport.http.HTTPConduit;
import org.apache.cxf.transports.http.configuration.HTTPClientPolicy;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
@Slf4j
public class CxfClientConfig {
@Value("${webservice.address}")
public String address;
// //
//import org.apache.cxf.endpoint.Client; @Value("${webservice.connecttime}")
//import org.apache.cxf.jaxws.JaxWsProxyFactoryBean; public int connecttime;
//import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory;
//import org.springframework.context.annotation.Bean; @Value("${webservice.receivetime}")
//import org.springframework.context.annotation.Configuration; public int receivetime;
// /**
//@Configuration *
//public class CxfClientConfig { *
// /** * @return NBAPlayerSoap
// * 采用代理方式 */
// *
// * @return NBAPlayerSoap
// */
//// @Bean
//// public NBAPlayerSoap createAuthorPortTypeProxy() {
//// JaxWsProxyFactoryBean jaxWsProxyFactoryBean = new JaxWsProxyFactoryBean();
//// jaxWsProxyFactoryBean.setServiceClass(NBAPlayerSoap.class);
//// jaxWsProxyFactoryBean.setAddress(WsConst.SERVICE_ADDRESS);
//// return (NBAPlayerSoap) jaxWsProxyFactoryBean.create();
//// }
//
// /**
// * 采用动态工厂方式 不需要指定服务接口
// * "http://www.webxml.com.cn/webservices/qqOnlineWebService.asmx?wsdl"
// *
// */
// @Bean // @Bean
// public Client createDynamicClient() { // public NBAPlayerSoap createAuthorPortTypeProxy() {
// JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance(); // JaxWsProxyFactoryBean jaxWsProxyFactoryBean = new JaxWsProxyFactoryBean();
// Client client = dcf.createClient("http://www.webxml.com.cn/webservices/qqOnlineWebService.asmx?wsdl"); // jaxWsProxyFactoryBean.setServiceClass(NBAPlayerSoap.class);
// return client; // jaxWsProxyFactoryBean.setAddress(WsConst.SERVICE_ADDRESS);
// } // return (NBAPlayerSoap) jaxWsProxyFactoryBean.create();
// } // }
/**
*
* "http://www.webxml.com.cn/webservices/qqOnlineWebService.asmx?wsdl"
*
*/
@Bean
public Client createDynamicClient() {
// 动态客户端
JaxWsDynamicClientFactory clientFactory = JaxWsDynamicClientFactory.newInstance();
log.info("实时数据 publicsecurity webService url : {}", address);
//根据WebServices接口地址创建client
Client client = clientFactory.createClient(address);
HTTPConduit conduit = (HTTPConduit) client.getConduit();
HTTPClientPolicy policy = new HTTPClientPolicy();
policy.setAllowChunking(false);
// 连接服务器超时时间 60秒
policy.setConnectionTimeout(connecttime);
// 等待服务器响应超时时间 60秒
policy.setReceiveTimeout(receivetime);
conduit.setClient(policy);
return client;
}
}

@ -1,37 +1,37 @@
package com.shxy.i2.configure; //package com.shxy.i2.configure;
//
import org.springframework.context.annotation.Bean; //import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; //import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync; //import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; //import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
//
import java.util.concurrent.Executor; //import java.util.concurrent.Executor;
import java.util.concurrent.ThreadPoolExecutor; //import java.util.concurrent.ThreadPoolExecutor;
//
//
@Configuration //@Configuration
@EnableAsync //@EnableAsync
public class ThreadPoolConfig { //public class ThreadPoolConfig {
//
/** // /**
* 线 // * 自定义线程池配置
* // *
* @return // * @return
*/ // */
@Bean(name = "asyncServiceExecutor") // @Bean(name = "asyncServiceExecutor")
public Executor asyncServiceExecutor() { // public Executor asyncServiceExecutor() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); // ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
//配置核心线程数 // //配置核心线程数
executor.setCorePoolSize(50); // executor.setCorePoolSize(50);
//配置最大线程数 // //配置最大线程数
executor.setMaxPoolSize(200); // executor.setMaxPoolSize(200);
//配置队列大小 // //配置队列大小
executor.setQueueCapacity(1000000); // executor.setQueueCapacity(1000000);
//配置线程池中的线程的名称前缀 // //配置线程池中的线程的名称前缀
executor.setThreadNamePrefix("async-cron-table"); // executor.setThreadNamePrefix("async-cron-table");
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy()); // executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
executor.initialize(); // executor.initialize();
return executor; // return executor;
} // }
//
} //}

@ -5,6 +5,8 @@ public interface Webservcies {
void uploadData(); void uploadData();
void uploadtxData();
void uploadyspData(); void uploadyspData();
void uploadjfjcData(); void uploadjfjcData();

@ -20,7 +20,7 @@ import java.util.List;
@Service @Service
@Slf4j @Slf4j
@EnableAsync //@EnableAsync
public class WebServiceImpl implements Webservcies { public class WebServiceImpl implements Webservcies {
@Autowired @Autowired
@ -55,62 +55,52 @@ public class WebServiceImpl implements Webservcies {
public void uploadData() { public void uploadData() {
log.info("实时数据定时任务启动"); log.info("实时数据定时任务启动");
// 动态客户端 // 动态客户端
JaxWsDynamicClientFactory clientFactory = JaxWsDynamicClientFactory.newInstance();
log.info("实时数据 publicsecurity webService url : {}", address);
//根据WebServices接口地址创建client
Client client = clientFactory.createClient(address);
HTTPConduit conduit = (HTTPConduit) client.getConduit();
HTTPClientPolicy policy = new HTTPClientPolicy();
policy.setAllowChunking(false);
// 连接服务器超时时间 60秒
policy.setConnectionTimeout(connecttime);
// 等待服务器响应超时时间 60秒
policy.setReceiveTimeout(receivetime);
conduit.setClient(policy);
log.info("开始执行定时任务-查询数据库"); log.info("开始执行定时任务-查询数据库");
HashMap<Integer, Niec_Sensors> equipMap = new HashMap(); HashMap<Integer, Niec_Sensors> equipMap = new HashMap();
List<Niec_Sensors> niec_sensors = niec_sensorsDao.selectAll(); List<Niec_Sensors> niec_sensors = niec_sensorsDao.selectAll();
for (Niec_Sensors item : niec_sensors) { for (Niec_Sensors item : niec_sensors) {
equipMap.put(item.getId(), item); equipMap.put(item.getId(), item);
} }
xydlI2Service.upload_sf6_qtyl(client, equipMap); xydlI2Service.upload_sf6_qtyl(null, equipMap);
xydlI2Service.upload_fhdlbx(client, equipMap); xydlI2Service.upload_fhdlbx(null, equipMap);
xydlI2Service.upload_fhzxq(client, equipMap); xydlI2Service.upload_fhzxq(null, equipMap);
xydlI2Service.upload_sf6_qtsf(client, equipMap); xydlI2Service.upload_sf6_qtsf(null, equipMap);
xydlI2Service.upload_tx(client, equipMap); xydlI2Service.upload_ws(null, equipMap);
xydlI2Service.upload_ws(client, equipMap); xydlI2Service.upload_dr_jyjc(null, equipMap);
xydlI2Service.upload_dr_jyjc(client, equipMap);
xydlI2Service.upload_microclimate(client, equipMap); xydlI2Service.upload_microclimate(null, equipMap);
xydlI2Service.upload_cnj(client, equipMap); xydlI2Service.upload_cnj(null, equipMap);
log.info("实时数据定时任务结束"); log.info("实时数据定时任务结束");
} }
@Override
public void uploadtxData() {
log.info("实时铁芯数据定时任务启动");
// 动态客户端
log.info("开始执行定时任务-查询数据库");
HashMap<Integer, Niec_Sensors> equipMap = new HashMap();
List<Niec_Sensors> niec_sensors = niec_sensorsDao.selectAll();
for (Niec_Sensors item : niec_sensors) {
equipMap.put(item.getId(), item);
}
xydlI2Service.upload_tx(null, equipMap);
log.info("实时数据定时任务结束");
}
//放到配置文件 //放到配置文件
@Override @Override
public void uploadyspData() { public void uploadyspData() {
log.info("油色谱数据定时任务启动"); log.info("油色谱数据定时任务启动");
// 动态客户端 // 动态客户端
JaxWsDynamicClientFactory clientFactory = JaxWsDynamicClientFactory.newInstance();
log.info("油色谱数据 publicsecurity webService url : {}", address);
//根据WebServices接口地址创建client
Client client = clientFactory.createClient(address);
HTTPConduit conduit = (HTTPConduit) client.getConduit();
HTTPClientPolicy policy = new HTTPClientPolicy();
policy.setAllowChunking(false);
// 连接服务器超时时间 60秒
policy.setConnectionTimeout(connecttime);
// 等待服务器响应超时时间 60秒
policy.setReceiveTimeout(receivetime);
conduit.setClient(policy);
log.info("开始执行定时任务-查询数据库"); log.info("开始执行定时任务-查询数据库");
HashMap<Integer, Niec_Sensors> equipMap = new HashMap(); HashMap<Integer, Niec_Sensors> equipMap = new HashMap();
List<Niec_Sensors> niec_sensors = niec_sensorsDao.selectAll(); List<Niec_Sensors> niec_sensors = niec_sensorsDao.selectAll();
for (Niec_Sensors item : niec_sensors) { for (Niec_Sensors item : niec_sensors) {
equipMap.put(item.getId(), item); equipMap.put(item.getId(), item);
} }
xydlI2Service.upload_ysp(client, equipMap); xydlI2Service.upload_ysp(null, equipMap);
log.info("油色谱数据定时任务结束"); log.info("油色谱数据定时任务结束");
} }
@ -118,25 +108,13 @@ public class WebServiceImpl implements Webservcies {
public void uploadjfjcData() { public void uploadjfjcData() {
log.info("局放监测数据定时任务启动"); log.info("局放监测数据定时任务启动");
// 动态客户端 // 动态客户端
JaxWsDynamicClientFactory clientFactory = JaxWsDynamicClientFactory.newInstance();
log.info("局放监测数据 publicsecurity webService url : {}", address);
//根据WebServices接口地址创建client
Client client = clientFactory.createClient(address);
HTTPConduit conduit = (HTTPConduit) client.getConduit();
HTTPClientPolicy policy = new HTTPClientPolicy();
policy.setAllowChunking(false);
// 连接服务器超时时间 60秒
policy.setConnectionTimeout(connecttime);
// 等待服务器响应超时时间 60秒
policy.setReceiveTimeout(receivetime);
conduit.setClient(policy);
HashMap<Integer, Niec_Sensors> equipMap = new HashMap(); HashMap<Integer, Niec_Sensors> equipMap = new HashMap();
List<Niec_Sensors> niec_sensors = niec_sensorsDao.selectAll(); List<Niec_Sensors> niec_sensors = niec_sensorsDao.selectAll();
for (Niec_Sensors item : niec_sensors) { for (Niec_Sensors item : niec_sensors) {
equipMap.put(item.getId(), item); equipMap.put(item.getId(), item);
} }
xydlI2Service.upload_dlq_jbfd(client, equipMap); xydlI2Service.upload_dlq_jbfd(null, equipMap);
xydlI2Service.upload_byq_jbfd(client, equipMap); xydlI2Service.upload_byq_jbfd(null, equipMap);
log.info("局放监测数据定时任务结束"); log.info("局放监测数据定时任务结束");
} }
@ -144,25 +122,13 @@ public class WebServiceImpl implements Webservcies {
public void uploadyxData() { public void uploadyxData() {
log.info("实时数据定时任务启动"); log.info("实时数据定时任务启动");
// 动态客户端 // 动态客户端
JaxWsDynamicClientFactory clientFactory = JaxWsDynamicClientFactory.newInstance();
log.info("实时数据 publicsecurity webService url : {}", address);
//根据WebServices接口地址创建client
Client client = clientFactory.createClient(address);
HTTPConduit conduit = (HTTPConduit) client.getConduit();
HTTPClientPolicy policy = new HTTPClientPolicy();
policy.setAllowChunking(false);
// 连接服务器超时时间 60秒
policy.setConnectionTimeout(connecttime);
// 等待服务器响应超时时间 60秒
policy.setReceiveTimeout(receivetime);
conduit.setClient(policy);
log.info("开始执行定时任务-查询数据库"); log.info("开始执行定时任务-查询数据库");
HashMap<Integer, Niec_Sensors> equipMap = new HashMap(); HashMap<Integer, Niec_Sensors> equipMap = new HashMap();
List<Niec_Sensors> niec_sensors = niec_sensorsDao.selectAll(); List<Niec_Sensors> niec_sensors = niec_sensorsDao.selectAll();
for (Niec_Sensors item : niec_sensors) { for (Niec_Sensors item : niec_sensors) {
equipMap.put(item.getId(), item); equipMap.put(item.getId(), item);
} }
xydlI2Service.upload_yx(client); xydlI2Service.upload_yx(null);
log.info("实时数据定时任务结束"); log.info("实时数据定时任务结束");
} }
@ -170,25 +136,13 @@ public class WebServiceImpl implements Webservcies {
public void uploaddcywData() { public void uploaddcywData() {
log.info("实时数据定时任务启动"); log.info("实时数据定时任务启动");
// 动态客户端 // 动态客户端
JaxWsDynamicClientFactory clientFactory = JaxWsDynamicClientFactory.newInstance();
log.info("实时数据 publicsecurity webService url : {}", address);
//根据WebServices接口地址创建client
Client client = clientFactory.createClient(address);
HTTPConduit conduit = (HTTPConduit) client.getConduit();
HTTPClientPolicy policy = new HTTPClientPolicy();
policy.setAllowChunking(false);
// 连接服务器超时时间 60秒
policy.setConnectionTimeout(connecttime);
// 等待服务器响应超时时间 60秒
policy.setReceiveTimeout(receivetime);
conduit.setClient(policy);
log.info("开始执行定时任务-查询数据库"); log.info("开始执行定时任务-查询数据库");
HashMap<Integer, Niec_Sensors> equipMap = new HashMap(); HashMap<Integer, Niec_Sensors> equipMap = new HashMap();
List<Niec_Sensors> niec_sensors = niec_sensorsDao.selectAll(); List<Niec_Sensors> niec_sensors = niec_sensorsDao.selectAll();
for (Niec_Sensors item : niec_sensors) { for (Niec_Sensors item : niec_sensors) {
equipMap.put(item.getId(), item); equipMap.put(item.getId(), item);
} }
xydlI2Service.upload_dcyw(client, equipMap); xydlI2Service.upload_dcyw(null, equipMap);
log.info("实时数据定时任务结束"); log.info("实时数据定时任务结束");
} }
@ -196,25 +150,13 @@ public class WebServiceImpl implements Webservcies {
public void uploadjsyhwjyjcData() { public void uploadjsyhwjyjcData() {
log.info("实时数据定时任务启动"); log.info("实时数据定时任务启动");
// 动态客户端 // 动态客户端
JaxWsDynamicClientFactory clientFactory = JaxWsDynamicClientFactory.newInstance();
log.info("实时数据 publicsecurity webService url : {}", address);
//根据WebServices接口地址创建client
Client client = clientFactory.createClient(address);
HTTPConduit conduit = (HTTPConduit) client.getConduit();
HTTPClientPolicy policy = new HTTPClientPolicy();
policy.setAllowChunking(false);
// 连接服务器超时时间 60秒
policy.setConnectionTimeout(connecttime);
// 等待服务器响应超时时间 60秒
policy.setReceiveTimeout(receivetime);
conduit.setClient(policy);
log.info("开始执行定时任务-查询数据库"); log.info("开始执行定时任务-查询数据库");
HashMap<Integer, Niec_Sensors> equipMap = new HashMap(); HashMap<Integer, Niec_Sensors> equipMap = new HashMap();
List<Niec_Sensors> niec_sensors = niec_sensorsDao.selectAll(); List<Niec_Sensors> niec_sensors = niec_sensorsDao.selectAll();
for (Niec_Sensors item : niec_sensors) { for (Niec_Sensors item : niec_sensors) {
equipMap.put(item.getId(), item); equipMap.put(item.getId(), item);
} }
xydlI2Service.upload_jsyhw_jyjc(client, equipMap); xydlI2Service.upload_jsyhw_jyjc(null, equipMap);
log.info("实时数据定时任务结束"); log.info("实时数据定时任务结束");
} }

@ -32,7 +32,7 @@ import java.util.List;
@Service @Service
@Slf4j @Slf4j
@EnableAsync //@EnableAsync
public class XydlI2ServiceImpl implements XydlI2Service { public class XydlI2ServiceImpl implements XydlI2Service {
@Autowired @Autowired

@ -1,8 +1,10 @@
package com.shxy.i2.timeTask; package com.shxy.i2.timeTask;
import com.shxy.i2.bean.AttrBean;
import com.shxy.i2.service.Webservcies; import com.shxy.i2.service.Webservcies;
import com.shxy.i2.service.XydlI2Service; import com.shxy.i2.service.XydlI2Service;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.cxf.endpoint.Client;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async; import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableAsync; import org.springframework.scheduling.annotation.EnableAsync;
@ -26,14 +28,13 @@ public class ScheduledTask {
@Autowired @Autowired
XydlI2Service xydlI2Service; XydlI2Service xydlI2Service;
@Scheduled(fixedDelay = 60 * 60 * 1000) @Scheduled(fixedDelay = 60 * 60 * 1000)
public void cacyspupload() { public void cacyspupload() {
log.info("cacyspupload执行" ); log.info("cacyspupload执行" );
webservcies.uploadyspData(); webservcies.uploadyspData();
} }
@Scheduled(fixedDelay = 5 * 60 * 1000) @Scheduled(fixedDelay = 1 * 30 * 1000)
public void cacjfjcupload() { public void cacjfjcupload() {
log.info("cacjfjcupload执行" ); log.info("cacjfjcupload执行" );
webservcies.uploadjfjcData(); webservcies.uploadjfjcData();
@ -45,6 +46,12 @@ public class ScheduledTask {
webservcies.uploadData(); webservcies.uploadData();
} }
@Scheduled(fixedDelay = 1 * 30 * 1000)
public void cactxupload() {
log.info("cactxupload执行" );
webservcies.uploadtxData();
}
@Scheduled(fixedDelay = 1 * 30 * 1000) @Scheduled(fixedDelay = 1 * 30 * 1000)
public void cacyxupload() { public void cacyxupload() {
log.info("cacyxupload执行" ); log.info("cacyxupload执行" );

Loading…
Cancel
Save