高分请教一个servlet存活时间问题

tidaly 2003-09-06 10:56:51
我写了一个servlet,一个while(true)循环的线程,参考代码如下:
public class SaveParam extends HttpServlet {
protected void doGet(
HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
TestThread test = new TestThread();
test.start();
}
}

public class TestThread extends Thread{
public void run(){
while(true){
try{
Thread.sleep(5000);
System.out.println("test is alive");
}catch(Exception e){
}
}
}
}
当客户端调用该servlet时,线程被启动,那么该线程能一直运行下去吗(我不关闭tomcat或servlet容器),有谁知道,请告诉我,多谢了!
...全文
52 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
qisong 2003-09-07
  • 打赏
  • 举报
回复
你应当做一个vector 把每个线程对象放到vector中,在程序中对其线程进行控制!
siuna 2003-09-07
  • 打赏
  • 举报
回复
请问 hesi726(hesi) :

tidaly(呆头鹅) 兄的程序怎么会多开线程呢?
Schlemiel 2003-09-06
  • 打赏
  • 举报
回复
servlet应该代表一个无状态的薄显示层,你干吗要做这种挑战极限的事情呢?
hesi726 2003-09-06
  • 打赏
  • 举报
回复
会!!!
不过多开了线称而已!
不过你的系统恐怕很快资源耗尽的了!!!!
tidaly 2003-09-06
  • 打赏
  • 举报
回复
但是servlet不是有个destroy()方法吗,tomcat系统是不是会自动调用这个方法对servlet进行销毁那?
jan4984 2003-09-06
  • 打赏
  • 举报
回复
是的, 可以一直运行下去。

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧