Code example for CountDownLatch

0
 
    public OFMessageFuture(IThreadPoolService tp,
            IOFSwitch sw, OFType responseType, int transactionId, long timeout, TimeUnit unit) {
        this.threadPool = tp;
        this.canceled = false;
        this.latch = new CountDownLatch(1);
        this.responseType = responseType;
        this.sw = sw;
        this.transactionId = transactionId;
 
        final OFMessageFuture<V> future = this;
        timeoutTimer = new Runnable() {
            @Override 
            public void run() { 
                if (timeoutTimer == this)
                    future.cancel(true);
            } 
        }; 
        threadPool.getScheduledExecutor().schedule(timeoutTimer, timeout, unit);
    }