- 浏览: 384344 次
- 性别:
- 来自: 北京
文章分类
最新评论
-
消失-IT超市:
方便加一下你的QQ吗,我的QQ是252375879,有个问题请 ...
js调用ocx控件(读写IC卡) -
mszb00123:
很有用
Extjs之--图片上传器 -
shouhouhuakai:
好崇拜,不错
URLConnection的连接、超时、关闭用法总结 -
wujierd:
写得好详细,学习了
URLConnection的连接、超时、关闭用法总结 -
paruke:
请问这个能加上图片旋转功能么 我试了一下 发现寻找中心点是个问 ...
Extjs之--图片浏览器
1、spring framework开发参考手册中第23掌"spring中的定时调度(Scheduling)和线程池(Thread Pooling)"提到三种方式:
(1)使用OpenSymphony Quartz 调度器
(2)使用JDK Timer支持类
(3)SpringTaskExecutor
抽象
2、实际业务需求说明
(1)同时向50台设备采集数据,并保存本地数据库。
(2)每30秒钟执行一次调度,完成对这50台设备数据的读取。
3、根据实际业务分析,属于多线程并发处理任务,于是采用SpringTaskExecutor
抽象方式完成
4、spring 容器配置
<!-- 接收数据 --> <!-- 异步线程池 --> <bean id="threadPool" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor"> <!-- 核心线程数 --> <property name="corePoolSize" value="10" /> <!-- 最大线程数 --> <property name="maxPoolSize" value="100" /> <!-- 队列最大长度 >=mainExecutor.maxSize --> <property name="queueCapacity" value="1000" /> <!-- 线程池维护线程所允许的空闲时间 --> <property name="keepAliveSeconds" value="300" /> <!-- 线程池对拒绝任务(无线程可用)的处理策略 --> <property name="rejectedExecutionHandler"> <bean class="java.util.concurrent.ThreadPoolExecutor$CallerRunsPolicy" /> </property> </bean> <bean id="collectSalesOrderExecutor" class="com.fts.internal.CollectSalesOrderExecutor"> <property name="threadPool" ref="threadPool" /> <property name="dataSource" ref="dataSource" /> </bean> <bean id="springScheduleExecutorTask" class="org.springframework.scheduling.concurrent.ScheduledExecutorTask"> <property name="runnable" ref="collectSalesOrderExecutor" /> <!-- 容器加载10秒后开始执行 --> <property name="delay" value="10000" /> <!-- 每次任务间隔 30秒--> <property name="period" value="30000" /> </bean> <bean id="springScheduledExecutorFactoryBean" class="org.springframework.scheduling.concurrent.ScheduledExecutorFactoryBean"> <property name="scheduledExecutorTasks" > <list> <ref bean="springScheduleExecutorTask" /> </list> </property> </bean>
5、java调用
(1) collectSalesOrderExecutor.java
public class CollectSalesOrderExecutor extends TimerTask { //注入ThreadPoolTaskExecutor 到主线程中 private ThreadPoolTaskExecutor threadPool; private JdbcTemplate template; public void setThreadPool(ThreadPoolTaskExecutor threadPool) { this.threadPool = threadPool; } //注入数据源 public void setDataSource(DataSource dataSource) { this.template = new JdbcTemplate(dataSource); } @Override public void run() { System.out.format("开始执行 %s ...%n", new Date()); @SuppressWarnings("unchecked") //取得设备列表 List<Equipment> ipList = template.query("select e.* from equipment e ", ParameterizedBeanPropertyRowMapper.newInstance(Equipment.class)); if (ipList != null) { for (Equipment equipment : ipList) { try { //执行向各个设备采集数据并保存数据库 threadPool.execute(new CollectSalesOrderTask(template,equipment.getIp())); } catch (Exception ex) { ex.printStackTrace(); } } } } }
(2)CollectSalesOrderTask.java
public class CollectSalesOrderTask implements Runnable { private String ip; private JdbcTemplate template; public CollectSalesOrderTask(JdbcTemplate template, String ip) { this.template = template; this.ip = ip; } @Override public void run() { // 连接设备 System.out.format("执行采集数据 %s ...%n", ip); //接收设备数据 List<Report> list = JhscaleCommunicationUtils.getDeviceSales(this.ip); //保存本地数据库 if (list != null && !list.isEmpty()) storeSalesOrder(list); } }
6、遇到的一个问题处理,即PC机作为服务器使用,可能长时间不关机,隔天之后会报如下错误:
Caused by: com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception:
原因:Mysql服务器默认的“wait_timeout”是8小时【也就是默认的值默认是28800秒】,也就是说一个connection空闲超过8个小时,Mysql将自动断开该connection,通俗的讲就是一个连接在8小时内没有活动,就会自动断开该连接。
解决:如下
D:\MySQL\MySQL Server 5.1\my.ini [mysqld] # The TCP/IP Port the MySQL Server will listen on port=3306 ---------位置下面添加----------- # this is myown dinifition for mysql connection timeout wait_timeout=31536000 interactive_timeout=31536000
发表评论
-
不负时光,继续学习
2017-04-11 17:04 6064月,一年当中最好的时节,和风煦日春意浓; ... -
生活依旧,做好自己
2017-02-04 16:51 385新年开工第二天,工作之余翻看了电脑上以前的文 ... -
2016年最后一天随笔
2016-12-30 14:48 5592016年马上就要过去了,回顾过去的一年感 ... -
excel中汉字转拼音全拼和简拼
2016-09-12 11:45 1511一、汉字转全拼 1.启动Excel 2003(其它版本请仿 ... -
年底总结3-工作中遇到的错误及解决方式
2015-02-16 11:28 983在过去的一年工作中遇到的一些问题及解决方式,如下: -- ... -
数据库方面遇到的问题总结
2013-05-23 20:29 9531、mysql服务自动关闭处理方式 我的电脑 -> ... -
resin2.1.17报错:META-INF/c.tld:6 unknown element `xsi:schemaLocation' in `taglib'
2012-08-20 18:37 30391、问题描述 resin启动后,访问jsp页面 ... -
Extjs grid 合计
2012-05-31 14:28 18761、直接在客户端统计,动态的修改Grid 2、代码如下 ... -
mysql函数使用-字符串处理
2012-05-29 17:15 11371、按地区统计数据 select q.psn,t.na ... -
spring JdbcTemplate 批量插入
2012-05-27 09:13 19961、通过批量操作减少与数据库连接所消耗的资源。 2、J ... -
JDBC连接Sql server
2012-03-07 10:24 16671、采用微软提供的ms sql server jdbc dri ... -
java下将汉字转换为拼音
2012-01-15 18:06 11661、代码如下,不过有些汉字不支持,如:茜 import ... -
年底总结1-tomcat6使用中遇到的问题
2012-01-01 10:23 65471、tomcat6.0.18注册windows服务成功后,但是 ... -
VML应用-利用ECOTree绘制树形结构图
2011-10-29 17:57 63221、基本概念 VML的全称是Vector Markup La ... -
java串口编程-读取称重仪表中净重
2011-10-12 17:08 5085一、需求说明 ... -
记录oracle 关联更新的例子
2011-10-03 20:55 11201、说明 修改某一天“本期值”数据时,需要把第二天的“上期值 ... -
Spring + JdbcTemplate + JdbcDaoSupport examples
2011-06-29 14:14 5503(转载)http://www.mkyong.com/sprin ... -
js--设为首页、加入收藏
2011-03-19 00:13 948<a onclick="this.style. ... -
org.hibernate.ObjectNotFoundException: No row with the given identifier exists
2011-03-08 00:19 20521、问题说明 hibenate中实体关联映射中<man ... -
VirtualBox网络配置-搭建数据库服务器
2011-02-10 23:50 31211、由于操作系统与数据库之间兼容性的问题,于是采用在虚拟机上安 ...
相关推荐
最新struts2-spring-plugin-2.3.24.1.jar
针对jms开发的架包 xbean-spring-3.9.jar
struts2-spring-plugin-2.2.1.jarstruts2-spring-plugin-2.2.1.jarstruts2-spring-plugin-2.2.1.jar
activiti-spring-boot-starter-basic-6.0.0适配springboot2.1.2
面试知识点总结--Spring 应用框架技术.pdf
spring4整合struts2所需要的jar包,缺少这个jar包则会报错
8、调度线程池:调度系统多线程触发调度运行,确保调度精确执行,不被堵塞; 9、弹性扩容缩容:一旦有新执行器机器上线或者下线,下次调度时将会重新分配任务; 10、邮件报警:任务失败时支持邮件报警,支持配置多...
struts2-spring-plugin-2.3.15.3.jar struts整合Spring的插件Jar包。
Spring实现任务调度.ppt Spring实现任务调度_代码演示 quartz-all-1.6.1.jar
面试知识点总结--spring面试题大全.pdf
logback与spring集成的文件,从官网上找的。上传的文件包括源文件和jar包,以下是连接: https://github.com/qos-ch/logback-extensions/wiki/Spring ...
struts2-spring-plugin-2.1.8.1.jar
参照阿里druid个人整理druid-spring-boot-starter可运行demo,细节方面自己完善
struts2-spring-plugin 最新jar包(2012.10.22) 0分资源,方便你我
struts2-spring-plugin-2.5.10.1.jar ---官方最新版本
struts2-spring-plugin-2.2.3.1.jar
- 多线程编程 2. 数据库: - 熟悉SQL语言 - 了解关系型数据库和非关系型数据库 - 数据库连接池 - 数据库事务 3. Spring框架: - Spring Boot - Spring MVC - Spring Data - Spring Security - Spring...
xbean-spring-2.4xbean-spring-2.4
spring任务调度(Quartz )非常基础,