因为http协议是被动的,所以只能在服务器端设置超时。如果你要在客户端设置超时属性的话,我觉得应该用socket类来编程。不知我说得是否正确。
gz
gz
解决方案 »
- (已经求教很多人,均无答案)何如将<xliff:g>标签写入xml文件中
- java初学者,菜鸟问题
- 新手求助!Eclipse中连接sqlserver2000数据库,用maven管理包,出现如下错误
- 各位大大看看这段代码有啥错的地方我找不到,我买的书里的代码运行时出错
- 如何设置从数据库中取出来的文字的颜色(jsp)?
- 一个简单的后台运行的java线程?
- public,protected,private,static,什么时候用,为什么要用,怎么用
- 大家来讨论一下java中得static得使用心得
- java中socket通讯的问题(连接过程中怎么判断网络中断?)
- 简单问题,给20分,安装过Jcreator的请进!!!
- 为什么在jb7中建立的web_app,有的jsp能编译而有些不能编译,请教
- ■■100分请问:学习WEBSPHERE,J2EE有没有好的中文资料介绍,或者学习经验技巧等,谢谢■■
import java.util.*;
public class ThreadTest extends Thread
{ public boolean flag = true;
public static ThreadTest t;
public void run() {
try {
HandlEvent h = new HandlEvent();
h.start();
sleep(3*1000);
if( flag ){
h.interrupt();
System.out.println("cao shi");
}
} catch(Exception e) {
}
}
public static void main(String[] args) {
t = new ThreadTest();
t.start();
}
class HandlEvent extends Thread{
public void run(){
try {
boolean ret = false;//youclass.testurl();
sleep(2*1000);
if( ret ){
t.flag = false;
System.out.println("do somthing");
}
} catch(Exception e){
}
}
}
}
自己做线程监控可行方案
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2002</p>
* <p>Company: </p>
* @author unascribed
* @version 1.0
*/public class Test {
public boolean testUrl(java.net.URL url){
class TestThread extends Thread{
public java.net.URL url;
public Thread parent ;
public boolean flag=false;
public TestThread(java.net.URL url){
this.url=url;
}
public void run(){
try{
System.out.println(new java.util.Date(System.currentTimeMillis()));
HttpURLConnection httpConnection = (HttpURLConnection)url.openConnection();
httpConnection.getURL();
int responseCode=httpConnection.getResponseCode();
if(responseCode==200){
flag= true;
parent.notify();
}
}catch(java.io.IOException e){
e.printStackTrace();
}
}
}
TestThread tt=new TestThread(url);
tt.start();
try{
Thread.currentThread().sleep(3000);
}catch(Exception e){
e.printStackTrace();
}
tt.stop();
System.out.println(new java.util.Date(System.currentTimeMillis()));
System.out.println("flag:"+tt.flag);
return tt.flag; }
public static void main(String[] args){
Test t=new Test();
try{
t.testUrl(new java.net.URL("http://www.sina.com.cn/"));
}catch(Exception e){
e.printStackTrace();
}
}
}