From fc1e415fb1e2bb14ae6bbcf85fedf2586132f0c4 Mon Sep 17 00:00:00 2001 From: liuguijing <123456> Date: Wed, 21 Feb 2024 13:50:25 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Di2=E5=86=85=E5=AD=98=E6=B3=84?= =?UTF-8?q?=E6=BC=8F=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/shxy/i2/I2Application.java | 4 +- .../java/com/shxy/i2/Tool/AsyncMethod.java | 17 +-- .../shxy/i2/configure/CxfClientConfig.java | 90 ++++++++----- .../shxy/i2/configure/ThreadPoolConfig.java | 74 +++++------ .../java/com/shxy/i2/service/Webservcies.java | 2 + .../shxy/i2/serviceimpl/WebServiceImpl.java | 120 +++++------------- .../i2/serviceimpl/XydlI2ServiceImpl.java | 2 +- .../com/shxy/i2/timeTask/ScheduledTask.java | 11 +- 8 files changed, 148 insertions(+), 172 deletions(-) diff --git a/src/main/java/com/shxy/i2/I2Application.java b/src/main/java/com/shxy/i2/I2Application.java index aa34ea9..870b0d5 100644 --- a/src/main/java/com/shxy/i2/I2Application.java +++ b/src/main/java/com/shxy/i2/I2Application.java @@ -20,8 +20,8 @@ import org.springframework.scheduling.annotation.EnableScheduling; @Slf4j @EnableConfigurationProperties @ComponentScan(basePackages = {"com.shxy"}) -@EnableCaching -@EnableAsync +//@EnableCaching +//@EnableAsync public class I2Application { public static void main(String[] args) { diff --git a/src/main/java/com/shxy/i2/Tool/AsyncMethod.java b/src/main/java/com/shxy/i2/Tool/AsyncMethod.java index 96bbba4..01fa9f5 100644 --- a/src/main/java/com/shxy/i2/Tool/AsyncMethod.java +++ b/src/main/java/com/shxy/i2/Tool/AsyncMethod.java @@ -10,8 +10,6 @@ import com.shxy.i2.dao.*; import lombok.extern.slf4j.Slf4j; import org.apache.cxf.endpoint.Client; 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 java.math.BigInteger; @@ -21,7 +19,7 @@ import java.util.List; @Slf4j @Component -@EnableAsync +//@EnableAsync public class AsyncMethod { @Autowired private Data_Dlq_JbfdDao data_dlq_jbfdDao; @@ -68,8 +66,11 @@ public class AsyncMethod { @Autowired private Upload_checkDao upload_checkDao; + @Autowired + private Client createDynamicClient; + - @Async(value = "asyncServiceExecutor") +// @Async(value = "asyncServiceExecutor") public void sendData(Client client, List idlist, String xml, String type) throws Exception { Object[] objects = client.invoke("uploadCACData", xml); 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 list1, String xml, String type) throws Exception { Object[] objects = client.invoke("uploadCACData", xml); 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 { - Object[] objects = client.invoke("uploadCACData", xml); + Object[] objects = createDynamicClient.invoke("uploadCACData", xml); String threadId = Thread.currentThread().getName(); log.info("线程序号: " + threadId + "当前时间:" + new Date()); 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 { // Object[] objects = client.invoke("uploadCACData", xml); // if (objects != null && objects.length > 0) { diff --git a/src/main/java/com/shxy/i2/configure/CxfClientConfig.java b/src/main/java/com/shxy/i2/configure/CxfClientConfig.java index 7f4af42..c93f741 100644 --- a/src/main/java/com/shxy/i2/configure/CxfClientConfig.java +++ b/src/main/java/com/shxy/i2/configure/CxfClientConfig.java @@ -1,35 +1,59 @@ -//package com.shxy.i2.configure; -// -//import org.apache.cxf.endpoint.Client; -//import org.apache.cxf.jaxws.JaxWsProxyFactoryBean; -//import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory; -//import org.springframework.context.annotation.Bean; -//import org.springframework.context.annotation.Configuration; -// -//@Configuration -//public class CxfClientConfig { -// /** -// * 采用代理方式 -// * -// * @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" -// * -// */ +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; + // + @Value("${webservice.connecttime}") + public int connecttime; + + @Value("${webservice.receivetime}") + public int receivetime; + /** + * 采用代理方式 + * + * @return NBAPlayerSoap + */ // @Bean -// public Client createDynamicClient() { -// JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance(); -// Client client = dcf.createClient("http://www.webxml.com.cn/webservices/qqOnlineWebService.asmx?wsdl"); -// return client; +// 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 + 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; + } +} diff --git a/src/main/java/com/shxy/i2/configure/ThreadPoolConfig.java b/src/main/java/com/shxy/i2/configure/ThreadPoolConfig.java index 2bdb251..33a6cb7 100644 --- a/src/main/java/com/shxy/i2/configure/ThreadPoolConfig.java +++ b/src/main/java/com/shxy/i2/configure/ThreadPoolConfig.java @@ -1,37 +1,37 @@ -package com.shxy.i2.configure; - -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.scheduling.annotation.EnableAsync; -import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; - -import java.util.concurrent.Executor; -import java.util.concurrent.ThreadPoolExecutor; - - -@Configuration -@EnableAsync -public class ThreadPoolConfig { - - /** - * 自定义线程池配置 - * - * @return - */ - @Bean(name = "asyncServiceExecutor") - public Executor asyncServiceExecutor() { - ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); - //配置核心线程数 - executor.setCorePoolSize(50); - //配置最大线程数 - executor.setMaxPoolSize(200); - //配置队列大小 - executor.setQueueCapacity(1000000); - //配置线程池中的线程的名称前缀 - executor.setThreadNamePrefix("async-cron-table"); - executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy()); - executor.initialize(); - return executor; - } - -} +//package com.shxy.i2.configure; +// +//import org.springframework.context.annotation.Bean; +//import org.springframework.context.annotation.Configuration; +//import org.springframework.scheduling.annotation.EnableAsync; +//import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; +// +//import java.util.concurrent.Executor; +//import java.util.concurrent.ThreadPoolExecutor; +// +// +//@Configuration +//@EnableAsync +//public class ThreadPoolConfig { +// +// /** +// * 自定义线程池配置 +// * +// * @return +// */ +// @Bean(name = "asyncServiceExecutor") +// public Executor asyncServiceExecutor() { +// ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); +// //配置核心线程数 +// executor.setCorePoolSize(50); +// //配置最大线程数 +// executor.setMaxPoolSize(200); +// //配置队列大小 +// executor.setQueueCapacity(1000000); +// //配置线程池中的线程的名称前缀 +// executor.setThreadNamePrefix("async-cron-table"); +// executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy()); +// executor.initialize(); +// return executor; +// } +// +//} diff --git a/src/main/java/com/shxy/i2/service/Webservcies.java b/src/main/java/com/shxy/i2/service/Webservcies.java index 9baec6a..4397d6c 100644 --- a/src/main/java/com/shxy/i2/service/Webservcies.java +++ b/src/main/java/com/shxy/i2/service/Webservcies.java @@ -5,6 +5,8 @@ public interface Webservcies { void uploadData(); + void uploadtxData(); + void uploadyspData(); void uploadjfjcData(); diff --git a/src/main/java/com/shxy/i2/serviceimpl/WebServiceImpl.java b/src/main/java/com/shxy/i2/serviceimpl/WebServiceImpl.java index 00ebd66..951c9e3 100644 --- a/src/main/java/com/shxy/i2/serviceimpl/WebServiceImpl.java +++ b/src/main/java/com/shxy/i2/serviceimpl/WebServiceImpl.java @@ -20,7 +20,7 @@ import java.util.List; @Service @Slf4j -@EnableAsync +//@EnableAsync public class WebServiceImpl implements Webservcies { @Autowired @@ -55,62 +55,52 @@ public class WebServiceImpl implements Webservcies { public void uploadData() { 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("开始执行定时任务-查询数据库"); HashMap equipMap = new HashMap(); List niec_sensors = niec_sensorsDao.selectAll(); for (Niec_Sensors item : niec_sensors) { equipMap.put(item.getId(), item); } - xydlI2Service.upload_sf6_qtyl(client, equipMap); + xydlI2Service.upload_sf6_qtyl(null, equipMap); - xydlI2Service.upload_fhdlbx(client, equipMap); - xydlI2Service.upload_fhzxq(client, equipMap); - xydlI2Service.upload_sf6_qtsf(client, equipMap); - xydlI2Service.upload_tx(client, equipMap); - xydlI2Service.upload_ws(client, equipMap); - xydlI2Service.upload_dr_jyjc(client, equipMap); + xydlI2Service.upload_fhdlbx(null, equipMap); + xydlI2Service.upload_fhzxq(null, equipMap); + xydlI2Service.upload_sf6_qtsf(null, equipMap); + xydlI2Service.upload_ws(null, equipMap); + xydlI2Service.upload_dr_jyjc(null, equipMap); - xydlI2Service.upload_microclimate(client, equipMap); - xydlI2Service.upload_cnj(client, equipMap); + xydlI2Service.upload_microclimate(null, equipMap); + xydlI2Service.upload_cnj(null, equipMap); log.info("实时数据定时任务结束"); } -//放到配置文件 + @Override + public void uploadtxData() { + log.info("实时铁芯数据定时任务启动"); + // 动态客户端 + log.info("开始执行定时任务-查询数据库"); + HashMap equipMap = new HashMap(); + List niec_sensors = niec_sensorsDao.selectAll(); + for (Niec_Sensors item : niec_sensors) { + equipMap.put(item.getId(), item); + } + xydlI2Service.upload_tx(null, equipMap); + log.info("实时数据定时任务结束"); + } + + + //放到配置文件 @Override public void uploadyspData() { 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("开始执行定时任务-查询数据库"); HashMap equipMap = new HashMap(); List niec_sensors = niec_sensorsDao.selectAll(); for (Niec_Sensors item : niec_sensors) { equipMap.put(item.getId(), item); } - xydlI2Service.upload_ysp(client, equipMap); + xydlI2Service.upload_ysp(null, equipMap); log.info("油色谱数据定时任务结束"); } @@ -118,25 +108,13 @@ public class WebServiceImpl implements Webservcies { public void uploadjfjcData() { 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 equipMap = new HashMap(); List niec_sensors = niec_sensorsDao.selectAll(); for (Niec_Sensors item : niec_sensors) { equipMap.put(item.getId(), item); } - xydlI2Service.upload_dlq_jbfd(client, equipMap); - xydlI2Service.upload_byq_jbfd(client, equipMap); + xydlI2Service.upload_dlq_jbfd(null, equipMap); + xydlI2Service.upload_byq_jbfd(null, equipMap); log.info("局放监测数据定时任务结束"); } @@ -144,25 +122,13 @@ public class WebServiceImpl implements Webservcies { public void uploadyxData() { 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("开始执行定时任务-查询数据库"); HashMap equipMap = new HashMap(); List niec_sensors = niec_sensorsDao.selectAll(); for (Niec_Sensors item : niec_sensors) { equipMap.put(item.getId(), item); } - xydlI2Service.upload_yx(client); + xydlI2Service.upload_yx(null); log.info("实时数据定时任务结束"); } @@ -170,25 +136,13 @@ public class WebServiceImpl implements Webservcies { public void uploaddcywData() { 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("开始执行定时任务-查询数据库"); HashMap equipMap = new HashMap(); List niec_sensors = niec_sensorsDao.selectAll(); for (Niec_Sensors item : niec_sensors) { equipMap.put(item.getId(), item); } - xydlI2Service.upload_dcyw(client, equipMap); + xydlI2Service.upload_dcyw(null, equipMap); log.info("实时数据定时任务结束"); } @@ -196,25 +150,13 @@ public class WebServiceImpl implements Webservcies { public void uploadjsyhwjyjcData() { 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("开始执行定时任务-查询数据库"); HashMap equipMap = new HashMap(); List niec_sensors = niec_sensorsDao.selectAll(); for (Niec_Sensors item : niec_sensors) { equipMap.put(item.getId(), item); } - xydlI2Service.upload_jsyhw_jyjc(client, equipMap); + xydlI2Service.upload_jsyhw_jyjc(null, equipMap); log.info("实时数据定时任务结束"); } diff --git a/src/main/java/com/shxy/i2/serviceimpl/XydlI2ServiceImpl.java b/src/main/java/com/shxy/i2/serviceimpl/XydlI2ServiceImpl.java index dd4d8f8..96f81bf 100644 --- a/src/main/java/com/shxy/i2/serviceimpl/XydlI2ServiceImpl.java +++ b/src/main/java/com/shxy/i2/serviceimpl/XydlI2ServiceImpl.java @@ -32,7 +32,7 @@ import java.util.List; @Service @Slf4j -@EnableAsync +//@EnableAsync public class XydlI2ServiceImpl implements XydlI2Service { @Autowired diff --git a/src/main/java/com/shxy/i2/timeTask/ScheduledTask.java b/src/main/java/com/shxy/i2/timeTask/ScheduledTask.java index 58886ce..1a49c33 100644 --- a/src/main/java/com/shxy/i2/timeTask/ScheduledTask.java +++ b/src/main/java/com/shxy/i2/timeTask/ScheduledTask.java @@ -1,8 +1,10 @@ package com.shxy.i2.timeTask; +import com.shxy.i2.bean.AttrBean; import com.shxy.i2.service.Webservcies; import com.shxy.i2.service.XydlI2Service; import lombok.extern.slf4j.Slf4j; +import org.apache.cxf.endpoint.Client; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.scheduling.annotation.Async; import org.springframework.scheduling.annotation.EnableAsync; @@ -26,14 +28,13 @@ public class ScheduledTask { @Autowired XydlI2Service xydlI2Service; - @Scheduled(fixedDelay = 60 * 60 * 1000) public void cacyspupload() { log.info("cacyspupload执行" ); webservcies.uploadyspData(); } - @Scheduled(fixedDelay = 5 * 60 * 1000) + @Scheduled(fixedDelay = 1 * 30 * 1000) public void cacjfjcupload() { log.info("cacjfjcupload执行" ); webservcies.uploadjfjcData(); @@ -45,6 +46,12 @@ public class ScheduledTask { webservcies.uploadData(); } + @Scheduled(fixedDelay = 1 * 30 * 1000) + public void cactxupload() { + log.info("cactxupload执行" ); + webservcies.uploadtxData(); + } + @Scheduled(fixedDelay = 1 * 30 * 1000) public void cacyxupload() { log.info("cacyxupload执行" );