title: java.net.BindException: Address already in use: bind - when stating tomcatx with jdk1.8 (not in debug mode)
body: <p>While setting up an environment for a tomcat project I ran into the exception</p>
  
  <pre><code>java.net.BindException: Address already in use: bind
  </code></pre>
  
  <p>The message is clear: the port is already used by some other process. So to troubleshoot I ran the following command</p>
  
  <pre><code> netstat -aon | find "&lt;port&gt;"
  </code></pre>
  
  <p>which returned nothing and thus suggests that the port is free for use by a new process.</p>
  
  <p>Here is my statup script for tomcat, note here the use of the jdk <code>1.8</code> as <code>JAVA_HOME</code></p>
  
  <pre><code>@ECHO OFF
  @SET JAVA_HOME=C:\Oracle\java\jdk1.8
  @SET CATALINA_HOME=C:\&lt;project&gt;\apache-tomcat-8.0
  @SET JAVA_OPTS=-Xmx512m -XX:MaxPermSize=128m
  @CALL %CATALINA_HOME%\bin\catalina.bat run
  </code></pre>
  
  <p>At first I though it was an issue with tomcat8, so I have tryied with <code>7</code> and <code>6</code> too. Same issue.</p>
  
  <p>After that, I stated to suspect the jdk, so I changed to <code>1.7</code> </p>
  
  <pre><code>@SET JAVA_HOME=C:\Oracle\java\jdk1.7
  </code></pre>
  
  <p>and the problem was gone, with the same port numbers and the three tomcats.</p>
  
  <p>So I checked my version of the jdk </p>
  
  <pre><code>Cmd-$&gt; %JAVA_HOME%\bin\java.exe -version
  java version "1.8.0"
  Java(TM) SE Runtime Environment (build 1.8.0-b132)
  Java HotSpot(TM) 64-Bit Server VM (build 25.0-b70, mixed mode)
  </code></pre>
  
  <p>and did an update (uninstall+install) to the latest version (at posting time)</p>
  
  <pre><code>Cmd-$&gt; %JAVA_HOME%\bin\java.exe -version
  java version "1.8.0_05"
  Java(TM) SE Runtime Environment (build 1.8.0_05-b13)
  Java HotSpot(TM) 64-Bit Server VM (build 25.5-b02, mixed mode)
  </code></pre>
  
  <p>So my questions are:</p>
  
  <ol>
  <li>Am I mistaken somewhere and is there anything else I could check?</li>
  <li>Is this a bug in the oracle's jdk 1.8, and if yes is there a workaound for this?</li>
  </ol>
  
  <p>If there is any other informations I should provide, please comment.</p>
  
  <p><strong>EIDT</strong> </p>
  
  <p>Running the sample code in the bug report referenced by @StephenC fails on the first time with jdk <code>1.8</code> and behaves as one would expect with my actual jdk version of <code>1.7</code>.</p>
  
  <pre><code>Cmd-$&gt; %JAVA_HOME%\bin\java.exe -version
  java version "1.7.0_17"
  Java(TM) SE Runtime Environment (build 1.7.0_17-b02)
  Java HotSpot(TM) 64-Bit Server VM (build 23.7-b01, mixed mode)
  </code></pre>
  
  <p>i.e. the first run is ok and the server responds correctly, the second fails with the expected <code>BindExcxeption</code>.</p>
  
  <p>The 1.7 jdk which presumably reproduces the bug according to the bug report is</p>
  
  <pre><code>java version "1.7.0_05"
  Java(TM) SE Runtime Environment (build 1.7.0_05-b05)
  Java HotSpot(TM) 64-Bit Server VM (build 23.1-b03, mixed mode)
  </code></pre>
  
  <p>Running Tomcat 7 from eclipse using the <a href="http://www.eclipsetotale.com/tomcatPlugin.html" rel="nofollow noreferrer">Sysdeo Eclipse Tomcat Launcher plugin</a> gave no BindException, here are my setting for the plugin</p>
  
  <p><img src="https://i.stack.imgur.com/KgTZQ.png" alt="enter image description here"></p>
  
  <p>I noticed though that the plugin runs <code>javaw.exe</code> not <code>java.exe</code>. I can't tell whether it makes a difference of not.</p>
  
  <p>Note that the tomxcat is ran in <code>debug</code> mode (the checkbox <code>Don't run Tomcat in debug mode</code> is not checked). If not ran in debug mode the exception comes.</p>
  
  <p>Also runnig tomcat from the script in debug mode using the <code>jpda</code> switch </p>
  
  <pre><code>@CALL %CATALINA_HOME%\bin\catalina.bat jpda run
  </code></pre>
  
  <p>seems to work around this issue.</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>Test on a 32 bit machine (+ 32 bit jdk and tomcat) were all successful with both jdk 1.8 and 1.7. Also the test class from the bug report behaves normally, i.e. BindException on second run.</p>
  
  <p><strong>UPDATE 2</strong></p>
  
  <p>The issue has survived a computer restart. Here is the output of the start process including the stacktrace, all other ports (AJP on 10009 and the server itself on 10005) are bound correctly:</p>
  
  <pre><code>Cmd-$&gt; starttc.bat
  Using CATALINA_BASE:   "C:\&lt;project&gt;\apache-tomcat-8.0"
  Using CATALINA_HOME:   "C:\&lt;project&gt;\apache-tomcat-8.0"
  Using CATALINA_TMPDIR: "C:\&lt;project&gt;\apache-tomcat-8.0\temp"
  Using JRE_HOME:        "C:\workspaces\Oracle\jdk1.8"
  Using CLASSPATH:       "C:\&lt;project&gt;\apache-tomcat-8.0\bin\bootstrap.jar;C:\&lt;project&gt;\apache-tomcat-8.0\bin\tomcat-juli.jar"
  Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=128m; support was removed in 8.0
  05-May-2014 09:16:08.043 INFO [main] org.apache.catalina.core.AprLifecycleListener.init The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\workspaces\Oracle\jdk1.8\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:\workspaces\Oracle\jdk1.6\bin;C:\oracle\product\11.2.0\dbhome_1\bin;C:\workspaces\Databases\oracle\product\11.2.0\dbhome_1\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Window
  s\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Novell\ZENworks\bin;C:\Program Files\SlikSvn\bin;C:\Program Files\TortoiseSVN\bin;C:\bin;C:\Program Files\SlikSvn\bin;C:\private\bin;C:\Oracle\jdk1.6\bin;C:\MinGW\bin;C:\Misc\c_c++\process builder;C:\Apache\apache-maven-3\bin;C:\tools\database\sqlite\bin;.
  05-May-2014 09:16:08.374 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["http-nio-10090"]
  05-May-2014 09:16:08.399 SEVERE [main] org.apache.coyote.AbstractProtocol.init Failed to initialize end point associated with ProtocolHandler ["http-nio-10090"]
   java.net.BindException: Address already in use: bind
          at sun.nio.ch.Net.bind0(Native Method)
          at sun.nio.ch.Net.bind(Net.java:414)
          at sun.nio.ch.Net.bind(Net.java:406)
          at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:214)
          at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:74)
          at org.apache.tomcat.util.net.NioEndpoint.bind(NioEndpoint.java:351)
          at org.apache.tomcat.util.net.AbstractEndpoint.init(AbstractEndpoint.java:683)
          at org.apache.coyote.AbstractProtocol.init(AbstractProtocol.java:456)
          at org.apache.coyote.http11.AbstractHttp11JsseProtocol.init(AbstractHttp11JsseProtocol.java:120)
          at org.apache.catalina.connector.Connector.initInternal(Connector.java:960)
          at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:102)
          at org.apache.catalina.core.StandardService.initInternal(StandardService.java:567)
          at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:102)
          at org.apache.catalina.core.StandardServer.initInternal(StandardServer.java:826)
          at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:102)
          at org.apache.catalina.startup.Catalina.load(Catalina.java:605)
          at org.apache.catalina.startup.Catalina.load(Catalina.java:630)
          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
          at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
          at java.lang.reflect.Method.invoke(Method.java:483)
          at org.apache.catalina.startup.Bootstrap.load(Bootstrap.java:310)
          at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:484)
  
  05-May-2014 09:16:08.402 SEVERE [main] org.apache.catalina.core.StandardService.initInternal Failed to initialize connector [Connector[HTTP/1.1-10090]]
   org.apache.catalina.LifecycleException: Failed to initialize component [Connector[HTTP/1.1-10090]]
          at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:106)
          at org.apache.catalina.core.StandardService.initInternal(StandardService.java:567)
          at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:102)
          at org.apache.catalina.core.StandardServer.initInternal(StandardServer.java:826)
          at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:102)
          at org.apache.catalina.startup.Catalina.load(Catalina.java:605)
          at org.apache.catalina.startup.Catalina.load(Catalina.java:630)
          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
          at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
          at java.lang.reflect.Method.invoke(Method.java:483)
          at org.apache.catalina.startup.Bootstrap.load(Bootstrap.java:310)
          at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:484)
  Caused by: org.apache.catalina.LifecycleException: Protocol handler initialization failed
          at org.apache.catalina.connector.Connector.initInternal(Connector.java:962)
          at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:102)
          ... 12 more
  Caused by: java.net.BindException: Address already in use: bind
          at sun.nio.ch.Net.bind0(Native Method)
          at sun.nio.ch.Net.bind(Net.java:414)
          at sun.nio.ch.Net.bind(Net.java:406)
          at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:214)
          at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:74)
          at org.apache.tomcat.util.net.NioEndpoint.bind(NioEndpoint.java:351)
          at org.apache.tomcat.util.net.AbstractEndpoint.init(AbstractEndpoint.java:683)
          at org.apache.coyote.AbstractProtocol.init(AbstractProtocol.java:456)
          at org.apache.coyote.http11.AbstractHttp11JsseProtocol.init(AbstractHttp11JsseProtocol.java:120)
          at org.apache.catalina.connector.Connector.initInternal(Connector.java:960)
          ... 13 more
  
  05-May-2014 09:16:08.404 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["ajp-nio-10009"]
  05-May-2014 09:16:08.453 INFO [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read
  05-May-2014 09:16:08.456 INFO [main] org.apache.catalina.startup.Catalina.load Initialization processed in 797 ms
  05-May-2014 09:16:08.484 INFO [main] org.apache.catalina.core.StandardService.startInternal Starting service Catalina
  05-May-2014 09:16:08.484 INFO [main] org.apache.catalina.core.StandardEngine.startInternal Starting Servlet Engine: Apache Tomcat/8.0.5
  05-May-2014 09:16:08.494 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory C:\&lt;project&gt;\apache-tomcat-8.0\webapps\docs
  05-May-2014 09:16:08.951 INFO [localhost-startStop-1] org.apache.catalina.util.SessionIdGenerator.createSecureRandom Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [151] milliseconds.
  05-May-2014 09:16:08.985 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory C:\&lt;project&gt;\apache-tomcat-8.0\webapps\examples
  05-May-2014 09:16:09.786 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory C:\&lt;project&gt;\apache-tomcat-8.0\webapps\host-manager
  05-May-2014 09:16:09.828 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory C:\&lt;project&gt;\apache-tomcat-8.0\webapps\manager
  05-May-2014 09:16:09.883 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory C:\&lt;project&gt;\apache-tomcat-8.0\webapps\ROOT
  05-May-2014 09:16:09.916 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["ajp-nio-10009"]
  05-May-2014 09:16:09.937 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in 1489 ms
  05-May-2014 09:17:30.430 INFO [Thread-5] org.apache.coyote.AbstractProtocol.pause Pausing ProtocolHandler ["http-nio-10090"]
  05-May-2014 09:17:30.431 INFO [Thread-5] org.apache.coyote.AbstractProtocol.pause Pausing ProtocolHandler ["ajp-nio-10009"]
  05-May-2014 09:17:30.498 INFO [Thread-5] org.apache.catalina.core.StandardService.stopInternal Stopping service Catalina
  05-May-2014 09:17:30.551 INFO [Thread-5] org.apache.coyote.AbstractProtocol.stop Stopping ProtocolHandler ["ajp-nio-10009"]
  05-May-2014 09:17:30.589 INFO [Thread-5] org.apache.coyote.AbstractProtocol.stop Stopping ProtocolHandler ["http-nio-10090"]
  05-May-2014 09:17:30.589 INFO [Thread-5] org.apache.coyote.AbstractProtocol.destroy Destroying ProtocolHandler ["http-nio-10090"]
  05-May-2014 09:17:30.590 INFO [Thread-5] org.apache.coyote.AbstractProtocol.destroy Destroying ProtocolHandler ["ajp-nio-10009"]
  </code></pre>