users@grizzly.java.net

Re: non-blocking connect etc

From: Oleksiy Stashok <Oleksiy.Stashok_at_Sun.COM>
Date: Fri, 03 Oct 2008 14:04:19 +0200

Hi Sebastien,

> A) I see that TCPConnectorHandler.connect() blocks until the
> connection is completed. Is there a way to do non-blocking outbound
> connect? I mean I don't want to exhaust my thread-pool in case I
> have many outgoing connections which don't complete within shortly.
TCPConnectorHandler.setConnectionTimeout(0);


> B) Thread-safety. Image you have two threads, threadA and threadB.
> threadA calls into TCPConnectorHandler.connect() and sets a new
> instance to the field isConnectedLatch at line 280 before calling
> selectorHandler.connect() on line 282. After that, threadB, which
> handles the onConnect() event, might call into this class via
> finishConnect() and try to access isConnectedLatch before threadA
> had a chance to complete line 283. Since isConnectedLatch is neither
> guarded by a lock nor volatile there is a risk of threadB not seeing
> the new value of isConnectedLatch (visibility) which threadA just
> wrote. Or am I misunderstanding something?
Hmm... Not sure I understand where the problem could occur :)
at line 280 threadA creates CountDownLatch(1), and never changes it
again, right?
ThreadB could call finishConnect either at time threadA will execute
line 282 or later. ThreadB can modify CountDownLatch, its internal
state, not a reference.

So, really don't see the problem here.

Thank you.

WBR,
Alexey.


>
>
>
> Thanks for the help
>
> Sebastian
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_grizzly.dev.java.net
> For additional commands, e-mail: users-help_at_grizzly.dev.java.net
>