解决方案 »

  1.   

    你每个端口检测都开一个线程去连socket,这个线程池里面的线程不会马上释放的,所以线程里面的finally方法socket.close();没有立即close,我觉得这是你程序过一段时间head剧增的最大原因观察一下是否内存增长的对象就是Socket呢?还有就是你减少检测的端口数量,或者增加线程池的max容量,看head的剧增时间是否推迟,如果是的话估计问题就在这上面了QQ交流:121102723
      

  2.   

    有趣的现象,JavaEE里估计不会有人回答,懂这方面的人不会关注这里。
      

  3.   

    go to anther website ask this la
      

  4.   

    if(start<0||end>=(1<<16)){
                System.err.println("The port number is illegal.");
                return;
            }这个1<<16是1左移呢还是16右移?
      

  5.   

    你呀,很好不错
    【下载】安卓图书及教学视频
    2014年4月微软MVP当选名单揭晓!
      

  6.   

    等到heap快满的时候将内存dump出来,分析下dump看看都是什么不回收的
      

  7.   

    IP换成127.0.0.1,在本地跑了下你的代码,到现在为止跑了10分钟了,没有出现你说的情况呀?我的jdk版本是1.6的。
    你的运行系统和jdk情况如何?
      

  8.   

    while(workQueue.size()>maximumPoolSize){
    你的workQueue东西,maximumPoolSize没起作用 线程数没能控制到。
    应该在for(int i=0;i<=maximumPoolSize;i++){}
    然后才是循环1-65535加到workQueue,遍历workQueue直到workQueue为空。
      

  9.   

    没注意看,workQueue是Runnable TCP的扫描速度很慢
    package com.demo.net;import java.net.InetSocketAddress;
    import java.net.Socket;
    import java.util.Queue;
    import java.util.concurrent.LinkedBlockingQueue;public class PortScanner {

    public static void main(String[] args) {
    String ip = "127.0.0.1";
    int start = 1;
    int end = 10000;
    Queue<Integer> portQueue = new LinkedBlockingQueue<Integer>();
    for (int i = start; i < end+1; i++) {
    portQueue.offer(i);
    }
    int threadCount = portQueue.size() >200?200:portQueue.size();
    ThreadGroup tg = new ThreadGroup("scan");
            for (int i = 0; i < threadCount; i++) {
                new Thread(tg,new Scan(ip,portQueue)).start();
            }
            while(true){
             if(tg.activeCount() == 0){
             break ;
             }
            }
            System.out.println("ok....");
    }
    }
    class Scan extends Thread{

    String ip;
    Queue<Integer> portQueue;

    public Scan(String ip,Queue<Integer> portQueue){
    this.ip = ip;
    this.portQueue = portQueue;
    }

    public void run(){
    while(true){
    try {
    int port = portQueue.poll();
    try {
    Socket s = new Socket();
    s.connect(new InetSocketAddress(ip, port));
    System.out.println(ip+":"+port);
    s.close();
    } catch (Exception e) {
    }
    } catch (NullPointerException e) {
    return ;
    }
    }
    }

    }