国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Java > 正文

java使用TimerTask定時器獲取指定網絡數據

2019-11-26 15:48:28
字體:
來源:轉載
供稿:網友

復制代碼 代碼如下:

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;

public class GetYinInfo extends TimerTask {
private void getCOMEXInfo() throws IOException{
String res = "";
SimpleDateFormat dateformat=new SimpleDateFormat("HH:mm:ss");
String df=dateformat.format(new Date());
URL url = new URL("http://www.survivalescaperooms.comI");
java.net.HttpURLConnection conn = (java.net.HttpURLConnection) url.openConnection();
conn.connect();
BufferedReader bf = new BufferedReader(new InputStreamReader(
conn.getInputStream(), "GBK"));
String line;
while ((line = bf.readLine()) != null) {
res += line;
}
String AGTD[]=res.split(",");
String re[]=AGTD[0].split(""");
System.out.println("COMEX "+df+":"+re[1]);
bf.close();
}
private void getTDInfo() throws IOException{
String res = "";
SimpleDateFormat dateformat=new SimpleDateFormat("HH:mm:ss");
String df=dateformat.format(new Date());
URL url = new URL(//www.survivalescaperooms.com);
java.net.HttpURLConnection conn = (java.net.HttpURLConnection) url.openConnection();
conn.connect();
BufferedReader bf = new BufferedReader(new InputStreamReader(
conn.getInputStream(), "GBK"));
String line;
while ((line = bf.readLine()) != null) {
res += line;
}
String AGTD[]=res.split(",");
String re[]=AGTD[0].split(""");
System.out.println("AG "+df+":"+re[1]);
bf.close();
}

@Override
public void run() {
try {
getCOMEXInfo();
getTDInfo();
System.out.println("---------------------------------------------");
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* @param args
*/
public static void main(String[] args) {
Timer timer = new Timer();
TimerTask t1 = new GetYinInfo();
//1000毫秒后,每隔1000毫秒運行一次t1任務
timer.schedule(t1,1000,5000);
/*try {
Thread.sleep(10000);
} catch (InterruptedException e) {
e.printStackTrace();
}
timer.cancel();*/
}
}

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 木里| 措勤县| 米脂县| 嘉鱼县| 乡城县| 定日县| 沙田区| 巩义市| 蕉岭县| 比如县| 大姚县| 原平市| 亳州市| 德令哈市| 承德市| 衡山县| 鹤壁市| 漳州市| 崇明县| 密云县| 清苑县| 金堂县| 砀山县| 得荣县| 富顺县| 宜兰市| 宿松县| 舞钢市| 沐川县| 乌拉特后旗| 聂拉木县| 安丘市| 鸡泽县| 化州市| 新巴尔虎左旗| 绵竹市| 桦南县| 宜君县| 中山市| 江孜县| 区。|