gpt4 book ai didi

java.net.BindException : Address already in use: bind - when stating tomcatx with jdk1. 8(未处于 Debug模式)

转载 作者:行者123 更新时间:2023-11-28 22:34:53 24 4
gpt4 key购买 nike

在为tomcat项目搭建环境时遇到了异常

java.net.BindException: Address already in use: bind

消息很清楚:该端口已被其他进程使用。所以为了排除故障,我运行了以下命令

 netstat -aon | find "<port>"

它没有返回任何内容,因此表明该端口可供新进程免费使用。

这是我的tomcat的statup脚本,注意这里使用jdk 1.8作为JAVA_HOME

@ECHO OFF
@SET JAVA_HOME=C:\Oracle\java\jdk1.8
@SET CATALINA_HOME=C:\<project>\apache-tomcat-8.0
@SET JAVA_OPTS=-Xmx512m -XX:MaxPermSize=128m
@CALL %CATALINA_HOME%\bin\catalina.bat run

起初我以为是 tomcat8 的问题,所以我也尝试了 76。同样的问题。

之后表示怀疑jdk,所以改成1.7

@SET JAVA_HOME=C:\Oracle\java\jdk1.7

问题消失了,端口号和三个 tomcat 相同。

所以我检查了我的jdk版本

Cmd-$> %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)

并更新(卸载+安装)到最新版本(在发布时)

Cmd-$> %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)

所以我的问题是:

  1. 我是不是哪里弄错了,还有什么我可以检查的吗?
  2. 这是 oracle 的 jdk 1.8 中的错误吗?如果是,是否有解决方法?

如果还有其他需要我提供的信息,请评论。

EIDT

第一次使用 jdk 1.8 运行@StephenC 引用的错误报告中的示例代码失败,并且表现与我的 1.7 实际 jdk 版本预期的一样.

Cmd-$> %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)

即第一次运行正常并且服务器响应正确,第二次运行失败并出现预期的 BindExcxeption

根据bug报告推测重现bug的1.7 jdk是

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)

使用 Sysdeo Eclipse Tomcat Launcher plugin 从 eclipse 运行 Tomcat 7 没有出现 BindException,这是我对插件的设置

enter image description here

我注意到插件运行的是 javaw.exe 而不是 java.exe。我不知道这是否会有所不同。

请注意,tomxcat 在调试 模式下运行(复选框Don't run Tomcat in debug mode 未选中)。如果未在 Debug模式下运行,则会出现异常。

还可以使用 jpda 开关在 Debug模式下从脚本运行 tomcat

@CALL %CATALINA_HOME%\bin\catalina.bat jpda run

似乎可以解决这个问题。

更新

在 32 位机器(+ 32 位 jdk 和 tomcat)上的测试在 jdk 1.8 和 1.7 上都成功了。错误报告中的测试类也表现正常,即第二次运行时出现 BindException。

更新 2

该问题在计算机重启后仍然存在。这是启动过程的输出,包括堆栈跟踪,所有其他端口(10009 上的 AJP 和 10005 上的服务器本身)都已正确绑定(bind):

Cmd-$> starttc.bat
Using CATALINA_BASE: "C:\<project>\apache-tomcat-8.0"
Using CATALINA_HOME: "C:\<project>\apache-tomcat-8.0"
Using CATALINA_TMPDIR: "C:\<project>\apache-tomcat-8.0\temp"
Using JRE_HOME: "C:\workspaces\Oracle\jdk1.8"
Using CLASSPATH: "C:\<project>\apache-tomcat-8.0\bin\bootstrap.jar;C:\<project>\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:\<project>\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:\<project>\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:\<project>\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:\<project>\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:\<project>\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"]

最佳答案

我认为您已被 Java 8 错误修复所困扰!

http://bugs.java.com/bugdatabase/view_bug.do?bug_id=7179799

如果您尝试绑定(bind)到已绑定(bind)的端口,Linux 和其他(非 Windows)操作系统上的 Java 总是会抛出异常。出于某种原因,这在某些 Windows 平台上的 Java 6 和 7 中是允许的。 Oracle 认为这是一个错误,并修复了它。

据推测,您正在运行 3 个 Tomcat 实例,它们都在与“穷人的”负载平衡器相同的端口上监听。您将需要找到另一种更可靠的方法来执行此操作。


更新

为了清楚起见,您不应该尝试在同一个端口上运行两个 Tomcat 实例。特别是生产服务器和测试服务器。

如果您确实设法让它“工作”,那么将不确定哪个实例会将请求发送到 IP/端口。有些可能会进入生产服务器,有些可能会进入测试服务器。简而言之,您的测试服务器将干扰您的生产服务器。

一个更好的主意是将您的测试 Tomcat 实例配置为监听与生产实例不同的端口和/或 IP 地址。

关于java.net.BindException : Address already in use: bind - when stating tomcatx with jdk1. 8(未处于 Debug模式),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23425688/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com