channel.closeFuture().sync(); is blocking and thus code never executes after this.

857 views
Skip to first unread message

devid....@gmail.com

unread,
Mar 27, 2014, 10:14:05 AM3/27/14
to ne...@googlegroups.com
Hi,

During migration from 3.6.6 to 4.0.17, I encountered blocking behavior due to channel.closeFuture().sync() statement. I know this is used to block the application until 
the server 's channel closed. But because of this we are unable to run the remaining code after this channel.closeFuture().sync(). 

Can get this done in another way where blocking can happen and the control comes back to the code ? 

I have asked this question already in another thread,  ( https://groups.google.com/forum/#!topic/netty/-gni59iE-Z0 )but I don't know who deleted my reply.. Anyhow, can you   answer the one ?


- Devid.

Norman Maurer

unread,
Mar 28, 2014, 3:00:11 PM3/28/14
to ne...@googlegroups.com, devid....@gmail.com
Just use:

ChannelFuture future = channel.closeFuture();
// do all you need here
future.sync();


-- 
Norman Maurer

JBoss, by Red Hat

--

---
You received this message because you are subscribed to the Google Groups "Netty discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to netty+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

devid....@gmail.com

unread,
Mar 29, 2014, 1:43:57 AM3/29/14
to ne...@googlegroups.com, devid....@gmail.com
In my scenarios, I want to run two servers, one is on http and other is https. 

ChannelFuture future1 = new insecure.WebSocketServer(7081).run();
future1.sync(); // as you said,

// this won't be reached. failing to start on other port.
ChannelFuture future2 = new secure.WebSocketSslServer(7444).run();
future2.sync();

-devid

Norman Maurer

unread,
Mar 31, 2014, 3:31:38 AM3/31/14
to ne...@googlegroups.com, devid....@gmail.com, devid....@gmail.com
Not sure why you not just do something like:

ChannelFuture future1 = new insecure.WebSocketServer(7081).run();

// this won't be reached. failing to start on other port.
ChannelFuture future2 = new secure.WebSocketSslServer(7444).run();
future2.sync();
future1.sync();

This way both futures must complete before anything else is done.
-- 
Norman Maurer

JBoss, by Red Hat


devid....@gmail.com

unread,
Apr 1, 2014, 7:31:38 AM4/1/14
to ne...@googlegroups.com, devid....@gmail.com
what's the difference with the previous statements ?

ChannelFuture future1 = new insecure.WebSocketServer(7081).run()

// this won't be reached. failing to start on other port.
ChannelFuture future2 = new secure.WebSocketSslServer(7444).run();
future2.sync();
future1.sync();

starting SslServer first and then start httpserver. I tried even this way, but no luck.

More ever, I have observed the following code in DefaultPromise<V> which implements a Promise<V>. When I call syn() method, it is going to wait() state. When will it be notified and who does that ?

@Override
    public Promise<V> await() throws InterruptedException {
        if (isDone()) {
            return this;
        }

        if (Thread.interrupted()) {
            throw new InterruptedException(toString());
        }

        synchronized (this) {
            while (!isDone()) {
                checkDeadLock();
                incWaiters();
                try {
                    wait();
                } finally {
                    decWaiters();
                }
            }
        }
        return this;
    }



-Devid.
Reply all
Reply to author
Forward
0 new messages