spring定时器
来源:互联网 发布:网络攻防技术pdf 编辑:程序博客网 时间:2024/05/01 18:34
package edu.xjtu.sei.timer;import java.net.HttpURLConnection;import java.net.URL;import java.util.List;import java.util.TimerTask;import edu.xjtu.sei.skyeye.state.dao.BotWallDAO;import edu.xjtu.sei.skyeye.state.po.BotWall;public class BotWallTimer extends TimerTask {private BotWallDAO botWallDAO;public void setBotWallDAO(BotWallDAO botWallDAO) {this.botWallDAO = botWallDAO;}@Overridepublic void run() {List<BotWall> list=botWallDAO.findAll();for (int i = 0; i < list.size(); i++) {BotWall bw=list.get(i);String ip=bw.getIp();String urlStr = "http://"+ip+":9066";boolean resule=exists(urlStr);if(resule){botWallDAO.timerMassage(ip, 1);}else {botWallDAO.timerMassage(ip, 0);}}} static boolean exists(String URLName) { try { //设置此类是否应该自动执行 HTTP 重定向(响应代码为 3xx 的请求)。 HttpURLConnection.setFollowRedirects(false); //到 URL 所引用的远程对象的连接 HttpURLConnection con = (HttpURLConnection) new URL(URLName) .openConnection(); /* 设置 URL 请求的方法, GET POST HEAD OPTIONS PUT DELETE TRACE 以上方法之一是合法的,具体取决于协议的限制。*/ con.setRequestMethod("HEAD"); //从 HTTP 响应消息获取状态码 return (con.getResponseCode() == HttpURLConnection.HTTP_OK); } catch (Exception e) { return false; } }}
一直通过http请求看连接是否有效。
<bean id="infoCenterAutoBuildTask" class="edu.xjtu.sei.skyeye.state.timer.BotWallTimer"> <property name="botWallDAO" ref="botWallDAO" /> </bean> <bean id="scheduledTask" class="org.springframework.scheduling.timer.ScheduledTimerTask"> <property name="delay" value="10000" /> <property name="period" value="1800000" /> <property name="timerTask" ref="infoCenterAutoBuildTask" /> </bean>
spring配置
- spring定时器
- Spring定时器
- Spring 定时器
- Spring定时器
- spring定时器
- Spring定时器
- spring 定时器
- Spring定时器
- spring定时器
- Spring定时器
- spring 定时器
- spring 定时器
- spring 定时器
- Spring定时器
- spring定时器
- spring 定时器
- spring 定时器
- spring定时器
- 编辑框被键盘遮挡解决办法!
- 每个程序员都应该知道的8个Linux命令
- 对于2 000 000 000 以内判断是否是素数 筛选法+暴力
- ASP.NET存储过程分页
- iBatis解决sql注入问题的方法
- spring定时器
- Ubuntu 10.04 Server下编译libjingle-0.6.14
- poj 3522 Slim Span(枚举+最小生成树)
- QT发布程序中文乱码完全解决方案 Qt for Windows
- Apache Shiro 架构
- c#查询部署机器的Office应用程序的版本
- undefined reference to `clock_gettime' 链接错误问题解决
- 一个基于HTML与JavaScript的Wizard演示
- python http