Occasional JMX-Port already in use error

A handful of times during development of a server using JMX, we've seen the following error:

[2007-03-24 13:26:59,489][Level: WARN][Thread:main][Could not detect RMI registry - creatingnew one] - [NDC:]

[2007-03-24 13:26:59,489][Level: INFO][Thread:main][An exception occurred during startup.

[exception:BeanCreationException][reason:Error creating bean with name'registry' defined inclass path

resource [proxyServerContext-jmx.xml]: Invocation of init method failed;

nested exception is *java.rmi.server.ExportException: Port already in use: 5000*; nested exception is:

java.net.BindException: Address already in use: JVM_Bind][stack trace:

org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1088)

org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:429)

org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:250)

org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:141)

org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:247)

org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:161)

org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:270)

org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:346)

org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:92)

...

It's been difficult to reproduce consistently or otherwise, but I'd feel more comfortable if we had some more insight into its possible causes.

The JMX configuration can be found in the post at http://forum.java.sun.com/thread.jspa?threadID=5131562&tstart=60.

BTW, if I simply start two instances of the server, I get a different error

[exception:BeanCreationException][reason

:Error creating bean with name'connectorServer' defined inclass path resource [proxyServerContext-jmx.xml]: Invocation

of init method failed; nested exception is java.io.IOException: Cannot bind to URL [rmi://localhost:5000/jmxrmi]: javax

.naming.NameAlreadyBoundException: jmxrmi [Root exception is java.rmi.AlreadyBoundException: jmxrmi]

so there is something different going on in the previous case I described...

Any insight would be appreciated.

Regards,

Steve

[2919 byte] By [Steve__Ta] at [2007-11-27 1:39:52]
# 1

Steve,

The most obvious explanation is that something else is listening to port 5000 when you launch your application. This "something else" isn't necessarily a program that is explicitly configured to use port 5000 - it might be a program that listens to "port 0", which the operating system converts into "some available port". If you're unlucky, that port might be 5000.

If you're on a Unix (or Unixlike) system you can use lsof to find what process is listening to port 5000: "lsof -i :5000". I don't know what the Windows equivalent might be.

Regards,

蒩monn McManus -- JMX Spec Lead -- http://weblogs.java.net/blog/emcmanus

emcmanusa at 2007-7-12 0:53:25 > top of Java-index,Core,Monitoring & Management...
# 2

Thanks, 蒩monn, that's helpful. I wasn't aware of the "port 0" acquisition.

I think the equivalent function on Windows is netstat -bv, and then look for the port of interest.

Steve

P.S. I'm going to hold a few Duke stars in reserve just in case someone else chimes in...

Message was edited by:

Steve__T

Steve__Ta at 2007-7-12 0:53:25 > top of Java-index,Core,Monitoring & Management...