【发布时间】:2012-12-24 04:28:17
【问题描述】:
我需要做的是能够停止从一个实现可运行的线程类运行的所有线程。这就是我的意思:这是我的“线程”类的开始:
public class HTTP extends Thread
{
int threadNumber;
String host;
int port;
int timeLeft;
private BufferedReader LocalBufferedReader;
public HTTP(int threadNumber, String host, int port, int timeLeft)
{
this.threadNumber = threadNumber;
this.host= host;
this.port = port;
this.timeLeft = (timeLeft * 1000);
}
public void run()
{
这就是我创建多个线程来执行此操作的方式:
for (int n = 1; n <= m; n++) {
new HTTP(n + 1, str, j, k).start();
}
m 是要创建的线程数。这可以是50-1000之间的任何地方。现在我需要做的就是立即停止所有这些。我怎样才能做到这一点?
【问题讨论】:
-
那是邪恶的,不要那样做。
-
最好的办法是有一个线程池来轮询HTTP对象(或者使用select和非阻塞io),每个HTTP方法的update方法会快速更新连接状态并返回。跨度>
-
更好的是使用现成的http服务器实现。
标签: java