环境:jxse-2.7, netty-3.6.6.Final
现象:每次执行都抛出以下异常
八月 08, 2013 8:45:19 下午 net.jxta.logging.Logging logCheckedInfo
INFO: Line 127 net.jxta.impl.endpoint.netty.NettyTransportServer.bindServerChannel()
Attempt to bind to /0.0.0.0:8080 failed (Address already in use: bind), trying another address
八月 08, 2013 8:45:19 下午 org.jboss.netty.channel.SimpleChannelUpstreamHandler
WARNING: EXCEPTION, please implement org.jboss.netty.channel.socket.httptunnel.TunnelWrappedServerChannelHandler.exceptionCaught() for proper handling.
java.net.BindException: Address already in use: bind
at sun.nio.ch.Net.bind0(Native Method)
at sun.nio.ch.Net.bind(Net.java:444)
at sun.nio.ch.Net.bind(Net.java:444)
at sun.nio.ch.Net.bind(Net.java:436)
at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:214)
at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:74)
at org.jboss.netty.channel.socket.nio.NioServerBoss$RegisterTask.run(NioServerBoss.java:193)
at org.jboss.netty.channel.socket.nio.AbstractNioSelector.processTaskQueue(AbstractNioSelector.java:366)
at org.jboss.netty.channel.socket.nio.AbstractNioSelector.run(AbstractNioSelector.java:290)
at org.jboss.netty.channel.socket.nio.NioServerBoss.run(NioServerBoss.java:42)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:724)
——————————————————————————————————————————————————————————————————
注意到黄色背景文字,显然8080端口被占用了;才想起最近安装Oracle Database 11g Express Edition,在安装时必须占用8080端口且无法修改。
停止Oracle服务,或按照《http://www.cnblogs.com/cuizhf/p/3246654.html》修改其端口。
上面的异常也说明Jxta绑定了8080端口(Why?),下面是NettyTransportServer初始化时的代码:
private void initServer(TCPAdv instanceConfiguration) throws PeerGroupException { this.serverEnabled = instanceConfiguration.isServerEnabled(); if(!serverEnabled) {
this.server = new NullTransportServerComponent();
return;
} String interfaceAddress = instanceConfiguration.getInterfaceAddress(); InetAddress bindAddr;
if(interfaceAddress != null) {
bindAddr = TransportUtils.resolveInterfaceAddress(interfaceAddress);
} else {
bindAddr = IPUtils.ANYADDRESS;
} String publicName = instanceConfiguration.getServer();
EndpointAddress publicAddress = null;
if (publicName != null) {
publicAddress = new EndpointAddress(protocolName, publicName, null, null);
} NettyTransportServer server = new NettyTransportServer(createServerSocketChannelFactory(), new InetSocketAddressTranslator(protocolName), group); int preferredPort = correctPort(instanceConfiguration.getPort(), 1, 65535, getDefaultPort(), getDefaultPort(), "Preferred");
int startPort = correctPort(instanceConfiguration.getStartPort(), 1, preferredPort, getDefaultPortRangeLowerBound(), 1, "Range start");
int endPort = correctPort(instanceConfiguration.getEndPort(), startPort, 65535, getDefaultPortRangeUpperBound(), 65535, "Range end");
List<InetSocketAddress> potentialBindpoints = IPUtils.createRandomSocketAddressList(bindAddr, preferredPort, startPort, endPort); server.init(potentialBindpoints, publicAddress, instanceConfiguration.getPublicAddressOnly());
this.server = server;
}