java怎么写一个计时器,再一段时间内执行某个任务,,到了时间或者任务完成终止 java计时 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 import java.io.FilterInputStream;import java.io.IOException;import java.net.MalformedURLException;import java.net.URL;public class CountNet { public static void main(String[] args) { int time = 0; while (true) { if (getCon() == 0) { time++; } try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } System.out.println("已经连接上了" + time + "秒"); } } public static int getCon() { URL url = null; // 构造一个下载的URL路径 try { url = new URL("http://www.baidu.com"); // 一个输入流 FilterInputStream in; in = (FilterInputStream) url.openStream(); // 关闭流对象 in.close(); } catch (MalformedURLException e) { return -1; } catch (IOException e) { e.printStackTrace(); } return 0; }} JAVA 动态 调用C++ 初学者问题 关于字符串的问题(急) JScroolPane的viewport中加入一个JPanel,如何实现导航功能 Ubuntu下编译Java出现问题.. 怎样用jsp把word表格的数据读如oracle数据库,各位大虾指点 熟悉Java program with Corba的高手请帮忙,谢谢 问几个关于 Eclipse 的问题 那儿有一些小程序的源代码看 Windows XP环境下Visual Age 3.5中运行Applet显示乱码的问题 为什么java rmi的helloworld程序不用生成stub也能运行 100分求一个正则表达式
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
public class CountNet {
public static void main(String[] args) {
int time = 0;
while (true) {
if (getCon() == 0) {
time++;
}
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("已经连接上了" + time + "秒");
}
}
public static int getCon() {
URL url = null; // 构造一个下载的URL路径
try {
url = new URL("http://www.baidu.com"); // 一个输入流
FilterInputStream in;
in = (FilterInputStream) url.openStream(); // 关闭流对象
in.close();
} catch (MalformedURLException e) {
return -1;
} catch (IOException e) {
e.printStackTrace();
} return 0;
}
}