public PortScan doScan(final PortListener portListener) {

        this.portListener = portListener;
        openPortsFound.clear();
        cancelled = false;

        new Thread(new Runnable() {
            @Override
            public void run() {

                ExecutorService executor = Executors.newFixedThreadPool(noThreads);

                for (int portNo : ports) {
                    Runnable worker = new PortScanRunnable(address, portNo, timeOutMillis, method);
                    executor.execute(worker);
                }

                // This will make the executor accept no new threads
                // and finish all existing threads in the queue
                executor.shutdown();
                // Wait until all threads are finish
                try {
                    executor.awaitTermination(1, TimeUnit.HOURS);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

                if (portListener != null) {
                    Collections.sort(openPortsFound);
                    portListener.onFinished(openPortsFound);
                }

            }
        }).start();

        return this;
    }
Perform an asynchronous (non-blocking) port scan

@param portListener - the listener to fire portscan results to.
@return - this object so we can cancel the scan if needed
library/src/main/java/com/stealthcopter/networktools/PortScan.java