我正在servlet中编写一个netty服务器。每次servlet由容器初始化时,它都会启动netty服务器。但我总是得到绑定异常,说“地址已经在使用:绑定”。我得到的例外情况如下。
java.net.BindException: Address already in use: bindAddress already in use: bind
at sun.nio.ch.Net.bind0(Native Method)
at sun.nio.ch.Net.bind(Unknown Source)
at sun.nio.ch.Net.bind(Unknown Source)
at sun.nio.ch.ServerSocketChannelImpl.bind(Unknown Source)
at sun.nio.ch.ServerSocketAdaptor.bind(Unknown Source)
at io.netty.channel.socket.nio.NioServerSocketChannel.doBind(NioServerSocketChannel.java:101)
at io.netty.channel.AbstractChannel$AbstractUnsafe.bind(AbstractChannel.java:474)
at io.netty.channel.DefaultChannelPipeline$HeadHandler.bind(DefaultChannelPipeline.java:995)
at io.netty.channel.DefaultChannelHandlerContext.invokeBind0(DefaultChannelHandlerContext.java:488)
at io.netty.channel.DefaultChannelHandlerContext.invokeBind(DefaultChannelHandlerContext.java:474)
at io.netty.channel.DefaultChannelHandlerContext.bind(DefaultChannelHandlerContext.java:468)
at io.netty.channel.DefaultChannelPipeline.bind(DefaultChannelPipeline.java:837)
at io.netty.channel.AbstractChannel.bind(AbstractChannel.java:193)
at io.netty.bootstrap.AbstractBootstrap$2.run(AbstractBootstrap.java:321)
at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:354)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:366)
at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:101)
at java.lang.Thread.run(Unknown Source)
那么,是否有人可以帮助摆脱这个问题。提前谢谢!
答案 0 :(得分:1)
某些东西已经在同一个端口上运行了。使用“netstat -tuplen”或“lsof -i | grep LISTEN”查找它是哪个进程。