当前位置: 技术问答>java相关
java多线程问题
来源: 互联网 发布时间:2014-12-29
本文导语: 我编了一个端口扫描程序(如下),但此程序经常漏掉一些端口。 我认为是程序中的block 1没有被所有的线程执行,该怎么办呢?谢谢! import java.io.*; import java.net.*; class scan implements Runnable{ static String host; ...
我编了一个端口扫描程序(如下),但此程序经常漏掉一些端口。
我认为是程序中的block 1没有被所有的线程执行,该怎么办呢?谢谢!
import java.io.*;
import java.net.*;
class scan implements Runnable{
static String host;
InetAddress hostaddress;
Socket socket;
BufferedReader socketinput;
DataOutputStream socketoutput;
static int i;
static int min,max;
public static void main(String args[]){
host="192.1.1.35";
ThreadGroup tg=new ThreadGroup("mytg");
scan s1=new scan();
Thread t1=new Thread(tg,s1);
t1.start();
scan s2=new scan();
Thread t2=new Thread(tg,s1);
t2.start();
scan s3=new scan();
Thread t3=new Thread(tg,s1);
t3.start();
scan s4=new scan();
Thread t4=new Thread(tg,s1);
t4.start();
scan s5=new scan();
Thread t5=new Thread(tg,s1);
t5.start();
scan s6=new scan();
Thread t6=new Thread(tg,s1);
t6.start();
for(;;){
if(tg.activeCount()==0){
System.out.println("the end");
break;
}
}
}
public void run(){
for(i=0;i
我认为是程序中的block 1没有被所有的线程执行,该怎么办呢?谢谢!
import java.io.*;
import java.net.*;
class scan implements Runnable{
static String host;
InetAddress hostaddress;
Socket socket;
BufferedReader socketinput;
DataOutputStream socketoutput;
static int i;
static int min,max;
public static void main(String args[]){
host="192.1.1.35";
ThreadGroup tg=new ThreadGroup("mytg");
scan s1=new scan();
Thread t1=new Thread(tg,s1);
t1.start();
scan s2=new scan();
Thread t2=new Thread(tg,s1);
t2.start();
scan s3=new scan();
Thread t3=new Thread(tg,s1);
t3.start();
scan s4=new scan();
Thread t4=new Thread(tg,s1);
t4.start();
scan s5=new scan();
Thread t5=new Thread(tg,s1);
t5.start();
scan s6=new scan();
Thread t6=new Thread(tg,s1);
t6.start();
for(;;){
if(tg.activeCount()==0){
System.out.println("the end");
break;
}
}
}
public void run(){
for(i=0;i