代码备忘-验证一个bug
来源:互联网 发布:太原理工软件算211吗 编辑:程序博客网 时间:2024/05/14 23:48
整理代码,发现某个加班的夜晚帮忙写的一段代码,为了验证一个时间延迟的bug:
package com.isoft.test;import java.io.BufferedReader;import java.io.InputStream;import java.io.InputStreamReader;import java.net.HttpURLConnection;import java.net.URL;import java.text.ParseException;import java.text.SimpleDateFormat;import java.util.Date;public class TestGetTime {private static SimpleDateFormat sdf = null;private static String serverTime = null;private static boolean isRun = true;/** * @param args * @throws Exception */public static void main(String[] args) throws Exception {sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");System.out.println("===========================================");TestGetTime test = new TestGetTime();test.printThread.start();}Thread printThread = new Thread(){@Overridepublic void run() {while(isRun){try {Thread.sleep(1000);printClientTime();pinrtServerTime();} catch (InterruptedException e) {e.printStackTrace();}}}};private static void printClientTime(){Date cDate = new Date();System.out.println("Client Time="+sdf.format(cDate));}private static long pinrtServerTime() {long time = 0;String urls = "http://192.168.60.99/test.php";try {URL url = new URL(urls);HttpURLConnection con = (HttpURLConnection) url.openConnection();con.connect();InputStream is = con.getInputStream();BufferedReader br = new BufferedReader(new InputStreamReader(is));String line;int index=0;while ((line = br.readLine()) != null) {serverTime = line;System.err.println("Server Time="+serverTime);Date sDate,cDate;try {sDate = sdf.parse(serverTime);cDate = new Date();long interval = (sDate.getTime()-cDate.getTime())/1000;System.err.println("sDate-cDate="+interval+"秒");if(Math.abs(interval)>=65){isRun = false;System.err.println("偶偶,出现异常了");}} catch (ParseException e) {// TODO Auto-generated catch blocke.printStackTrace();}}con.disconnect();} catch (Exception e) {e.printStackTrace();}return time;}}
- 代码备忘-验证一个bug
- eboot中的一个bug与备忘
- eboot中的一个bug与备忘
- bug备忘
- 一个验证码检查代码
- 解决打印代码的一个Bug
- 解决打印代码的一个Bug
- 发现storm代码的一个Bug
- 备忘代码
- 代码备忘
- 代码备忘
- 代码备忘
- junit的一个bug+实例验证+解决方案(两种)
- 关于validate验证表单与js语法的一个bug
- DELPHI中BUG修改备忘
- 一个很流行的表单验证代码
- 一个验证码识别的代码
- c#写的一个验证码代码
- 骑士走棋盘
- pow数学函数
- linux kernel note
- Android之MVC模式
- C语言学习成长之路第一篇
- 代码备忘-验证一个bug
- Create and Pulish web service, call in Asp.net(Demo).
- 单件模式
- POJ 1273 || HDU 1532 Drainage Ditches ,最大流入门题
- 新手学习C语言常见几个错误以及处理方式
- 嵌入式linux下usb驱动开发方法--看完少走弯路
- jquery 通过flash多文件上传 实现IE和firefox兼容 java版
- 新建service模板
- Linux常用命令大全