Le 01/12/14 10:59, 주재경 a écrit :
> Your reply is very helpful but I'm not english speaker 

Neither do I, not most of the users on the mailing list. It's not a
shame ;-)

> so I should check what I understand.
> Below is sample of my code.
> getConnect() method return global instance.
> Should I add synchronized statement or not?
>
>       public void sessionClosed(IoSession session) throws Exception {
>               reconnectSession(session);
>       }
>
>       static public void reconnectSession(final IoSession session, final 
> NpsConf npsConf, final Integer index) {
>               Thread thread = new Thread(new Runnable() {
>                       public void run() {
>                               try {
>                                       ...
>                                       final IoConnector connector = 
> MainContext.getInstance().getConnector();
>                                       connectFuture = 
> connector.connect(ipAddress, port);
>                                       ...
>
> or
>
>                                       ...
>                                       final IoConnector connector = 
> MainContext.getInstance().getConnector();
>                                       synchronized(connector) {
>                                               connectFuture = 
> connector.connect(ipAddress, port);
>                                       }
>                                       ...
>
> Which is correct?

I hope you are not recreating a new Connector instance in
MainContext.getInstance().getConnector();...


Again, it all depends on what you do in the chain. If you have added
some interceptors that are not thread safe, then you might have a
problem with the not synchronized form.

Overall, I would assume that the non-synchronized form is safe.

What I would ask here, beside any theorical and rethorical question
about thread safety, is why you may think that you have pb with this
very part of your code ? Do you have any element taht make you think
that thi sis a problem not to use a synhronized connection?

Ie, bring some evidences. If you think you have a problem, it's because
your code is not behaving the way you expect it to do, so please provide
us with your findings...



Reply via email to