我想在Servlet中,根据request参数做为线程的名字来创建线程,如下:
...
public void doPost(...){
...
String threadId = request.getParameter("threadid");
TestThread tt = new TestThread(threadId);
...
}TestThread类
public class TestThread extends Thread{
...
public TestThread(String threadId){
this.setName(threadId);
this.start();
}
...
}
我这样写对吗?
现在我想根据创建线程时的名字threadId来管理线程,该如何做呢?
...
public void doPost(...){
...
String threadId = request.getParameter("threadid");
TestThread tt = new TestThread(threadId);
...
}TestThread类
public class TestThread extends Thread{
...
public TestThread(String threadId){
this.setName(threadId);
this.start();
}
...
}
我这样写对吗?
现在我想根据创建线程时的名字threadId来管理线程,该如何做呢?
构造函数的start()应该写在doPost里面,以免引起不必要的麻烦
你最好用tt来管理线程
也就是说多个线程你可以用数组来管理,名字应该只是为了方便查错,根据我的经验来说
然后用get方法拿出来