title: Why Java opens 3 ports when JMX is configured?
body: <p>I run my Java program with JDK7 on Centos6. I enable JMX using the following options:</p>
  
  <pre><code>JAVA_OPTS="${JAVA_OPTS} -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=9123 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.local.only=true"
  </code></pre>
  
  <p>When I check what ports are opened I discover 2 additional random ports:</p>
  
  <pre><code>netstat -plunt | grep java
  tcp        0      0 :::9123                     :::*                        LISTEN      13295/java
  tcp        0      0 :::59927                    :::*                        LISTEN      13295/java
  tcp        0      0 :::59928                    :::*                        LISTEN      13295/java
  </code></pre>
  
  <p>Please note that each restart only configured port 9123 remains same, and two additional ports change values.</p>
  
  <pre><code>netstat -plunt | grep java
  tcp        0      0 :::9123                     :::*                        LISTEN      13331/java
  tcp        0      0 :::59932                    :::*                        LISTEN      13331/java
  tcp        0      0 :::59933                    :::*                        LISTEN      13331/java
  </code></pre>
  
  <p>What are 2 additional ports and why they are opened? </p>
  
  <p>How can I configure 2 additional random ports?</p>
  
  <p>How can I configure <code>::ffff:127.0.0.1</code> will appear before all ports opened by JMX?</p>
  
  <p>Why one port is not used when connecting with JConsole?</p>
  
  <p><strong>Added to clarify the answer</strong></p>
  
  <p>Unfortunately, the additional random port is still opened
  To remind you, I use Centos 6.
  My Tomcat settings are look like this (Tomcat does not deploy any applications):</p>
  
  <pre><code>CATALINA_OPTS="${CATALINA_OPTS}  -XX:+DisableAttachMechanism -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.local.only=true -Djava.rmi.server.useLocalHostname=true -Djava.rmi.server.useCodebaseOnly=true -Dcom.sun.management.jmxremote.port=9123 -Dcom.sun.management.jmxremote.rmi.port=9123"
  </code></pre>
  
  <p>Tomcat process looks like this:</p>
  
  <pre><code>/usr/java/jdk1.7.0_51/bin/java -Djava.util.logging.config.file=/usr/tomcat-7.0.47/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -XX:+DisableAttachMechanism -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.local.only=true -Djava.rmi.server.useLocalHostname=true -Djava.rmi.server.useCodebaseOnly=true -Dcom.sun.management.jmxremote.port=9123 -Dcom.sun.management.jmxremote.rmi.port=9123 -Djava.endorsed.dirs=/usr/tomcat-7.0.47/endorsed -classpath /usr/tomcat-7.0.47/bin/bootstrap.jar:/usr/tomcat-7.0.47/bin/tomcat-juli.jar -Dcatalina.base=/usr/tomcat-7.0.47 -Dcatalina.home=/usr/tomcat-7.0.47 -Djava.io.tmpdir=/usr/tomcat-7.0.47/temp org.apache.catalina.startup.Bootstrap start
  </code></pre>
  
  <p>Unfortunately, each time I see additional listening port:</p>
  
  <pre><code>tcp        0      0 :::38830                    :::*                        LISTEN      790/java
  tcp        0      0 ::ffff:127.0.0.1:8080       :::*                        LISTEN      790/java
  tcp        0      0 :::9123                     :::*                        LISTEN      790/java
  </code></pre>
  
  <p>Additional run:</p>
  
  <pre><code>tcp        0      0 ::ffff:127.0.0.1:8080       :::*                        LISTEN      2348/java
  tcp        0      0 :::36252                    :::*                        LISTEN      2348/java
  tcp        0      0 :::9123                     :::*                        LISTEN      2348/java
  </code></pre>
  
  <p>BTW, why I can not see <code>::ffff:127.0.0.1</code> before RMI ports?</p>
  
  <p><strong>Added second time to clarify the comment</strong></p>
  
  <p>It is not related to Tomcat. I have tried to run ant with similar settings:
  Ant process looks like this:</p>
  
  <pre><code>/usr/bin/java -XX:+DisableAttachMechanism -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.local.only=true -Djava.rmi.server.useLocalHostname=true -Djava.rmi.server.useCodebaseOnly=true -Dcom.sun.management.jmxremote.port=9123 -Dcom.sun.management.jmxremote.rmi.port=9123 -classpath /usr/apache-ant-1.9.2/lib/ant-launcher.jar -Dant.home=/usr/apache-ant-1.9.2 -Dant.library.dir=/usr/apache-ant-1.9.2/lib org.apache.tools.ant.launch.Launcher -cp  sleep
  </code></pre>
  
  <p>Unfortunately, each time I see additional listening port:</p>
  
  <pre><code>tcp        0      0 :::41200                    :::*                        LISTEN      13597/java
  tcp        0      0 :::9123                     :::*                        LISTEN      13597/java
  </code></pre>
  
  <p>Additional run:</p>
  
  <pre><code>tcp        0      0 :::58356                    :::*                        LISTEN      13629/java
  tcp        0      0 :::9123                     :::*                        LISTEN      13629/java
  </code></pre>
  
  <p><strong>Answer: It is Java's bug</strong></p>
  
  <p>I success to open bug on Java:
  <a href="http://bugs.java.com/bugdatabase/view_bug.do?bug_id=8035404">http://bugs.java.com/bugdatabase/view_bug.do?bug_id=8035404</a></p>