在一个servlet中启动4个线程,4个线程不停的运行,如下:public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
TestThread [] tt=new TestThread[4];
for(int i=0;i<tt.length;i++)
{
tt[i]=new TestThread();
tt[i].start();
}
}我将这个webAPP传到空间,访问这个servlet,4个线程都启动了,但是过一段时间发现4个线程都停了。
这是为什么?
我试过哪怕是一个线程都不行。有什么好的办法?
throws ServletException, IOException {
TestThread [] tt=new TestThread[4];
for(int i=0;i<tt.length;i++)
{
tt[i]=new TestThread();
tt[i].start();
}
}我将这个webAPP传到空间,访问这个servlet,4个线程都启动了,但是过一段时间发现4个线程都停了。
这是为什么?
我试过哪怕是一个线程都不行。有什么好的办法?
{
public void run() {
while(true)
{
//读取Socket通讯得到的值插入数据库
}
}
}