Apache Mina Server Restart java.net.BindException: Address already in use

Posted by Kosaki on Stack Overflow See other posts from Stack Overflow or by Kosaki
Published on 2010-03-09T17:30:05Z Indexed on 2010/05/09 12:08 UTC
Read the original article Hit count: 721

Filed under:
|
|
|

Hello, I have a rather annoying problem in my server application.

I bind Apache Mina with the following code:

acceptor.bind(new InetSocketAddress(PORT));

Where acceptor is an NioSocketAcceptor. Over a HTTP interface I can shutdown the server so I can restart it.

Server.ioAcceptor.unbind(new InetSocketAddress(Server.PORT));
        for(IoSession session: Server.ioAcceptor.getManagedSessions().values()){
            if(session.isConnected() && !session.isClosing()){
                session.close(false);
            }
        }
        Server.ioAcceptor.dispose();

        Main.transport.stop();
        Logger.getRootLogger().warn("System going down. Request from "+context.getRemoteAddress());
        System.exit(10);       

This is the code I use to stop the Mina server. However if I try to start the server again in the next couple of minutes. (Somewhere between 5 minutes and 15 minutes) I get the following exception on start up: java.net.BindException: Address already in use

I also tried a simple ioAcceptor.unbind() but there was no difference. The server runs on Centos 5 with OpenJDK. Apache Mina version is 2.0 RC1.

Thank you in advance for any ideas on how to resolve this.

© Stack Overflow or respective owner

Related posts about apache-mina

Related posts about java