NetBeans运行Java代码(Web服务)两次

时间:2015-12-10 13:27:48

标签: java web-services netbeans tomcat8 netbeans-8.1

我们有一个代码(webservice),我们希望它运行一次,但运行两次。我们无法找出它运行两次的原因。这是一个简化的Hello World示例:

Hello !

这是日志的一部分。您可以看到第13行和第31行中有两个10-Dec-2015 15:04:01.476 INFO [localhost-startStop-1] com.sun.xml.ws.server.MonitorBase.createRoot Metro monitoring rootname successfully set to: com.sun.metro:pp=/,type=WSEndpoint,name=/LogoMobim-WebServices-WebServicesPort 10-Dec-2015 15:04:01.769 INFO [localhost-startStop-1] com.sun.xml.ws.transport.http.servlet.WSServletDelegate.<init> WSSERVLET14: JAX-WS servlet initializing 10-Dec-2015 15:04:01.794 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDescriptor Deployment of configuration descriptor C:\Users\logo\AppData\Roaming\NetBeans\8.1\apache-tomcat-8.0.27.0_base\conf\Catalina\localhost\LogoMobim.xml has finished in 7,365 ms 10-Dec-2015 15:04:01.794 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDescriptor Deploying configuration descriptor C:\Users\logo\AppData\Roaming\NetBeans\8.1\apache-tomcat-8.0.27.0_base\conf\Catalina\localhost\manager.xml 10-Dec-2015 15:04:01.880 INFO [localhost-startStop-1] org.apache.jasper.servlet.TldScanner.scanJars At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time. 10-Dec-2015 15:04:01.885 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDescriptor Deployment of configuration descriptor C:\Users\logo\AppData\Roaming\NetBeans\8.1\apache-tomcat-8.0.27.0_base\conf\Catalina\localhost\manager.xml has finished in 91 ms 10-Dec-2015 15:04:01.885 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDescriptor Deploying configuration descriptor C:\Users\logo\AppData\Roaming\NetBeans\8.1\apache-tomcat-8.0.27.0_base\conf\Catalina\localhost\ROOT.xml 10-Dec-2015 15:04:01.951 INFO [localhost-startStop-1] org.apache.jasper.servlet.TldScanner.scanJars At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time. 10-Dec-2015 15:04:01.953 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDescriptor Deployment of configuration descriptor C:\Users\logo\AppData\Roaming\NetBeans\8.1\apache-tomcat-8.0.27.0_base\conf\Catalina\localhost\ROOT.xml has finished in 68 ms 10-Dec-2015 15:04:01.953 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDescriptor Deploying configuration descriptor C:\Users\logo\AppData\Roaming\NetBeans\8.1\apache-tomcat-8.0.27.0_base\conf\Catalina\localhost\WebServiceTest.xml 10-Dec-2015 15:04:03.683 INFO [localhost-startStop-1] org.apache.jasper.servlet.TldScanner.scanJars At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time. 10-Dec-2015 15:04:03.694 INFO [localhost-startStop-1] com.sun.xml.ws.transport.http.servlet.WSServletContextListener.contextInitialized WSSERVLET12: JAX-WS context listener initializing Hello ! 10-Dec-2015 15:04:06.970 INFO [localhost-startStop-1] com.sun.xml.ws.server.MonitorBase.createRoot Metro monitoring rootname successfully set to: com.sun.metro:pp=/,type=WSEndpoint,name=/WebServiceTest-HelloService-HelloPort 10-Dec-2015 15:04:07.132 INFO [localhost-startStop-1] com.sun.xml.ws.transport.http.servlet.WSServletDelegate.<init> WSSERVLET14: JAX-WS servlet initializing 10-Dec-2015 15:04:07.136 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDescriptor Deployment of configuration descriptor C:\Users\logo\AppData\Roaming\NetBeans\8.1\apache-tomcat-8.0.27.0_base\conf\Catalina\localhost\WebServiceTest.xml has finished in 5,182 ms 10-Dec-2015 15:04:07.140 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-nio-8084"] 10-Dec-2015 15:04:07.148 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["ajp-nio-8009"] 10-Dec-2015 15:04:07.156 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in 12776 ms 10-Dec-2015 15:04:07.358 INFO [http-nio-8084-exec-7] com.sun.xml.ws.transport.http.servlet.WSServletDelegate.destroy WSSERVLET15: JAX-WS servlet destroyed 10-Dec-2015 15:04:07.359 INFO [http-nio-8084-exec-7] com.sun.xml.ws.server.MonitorBase.closeMOM Closing Metro monitoring root: com.sun.metro:pp=/,type=WSEndpoint,name=/WebServiceTest-HelloService-HelloPort 10-Dec-2015 15:04:07.359 INFO [http-nio-8084-exec-7] com.sun.xml.ws.transport.http.servlet.WSServletContextListener.contextDestroyed WSSERVLET13: JAX-WS context listener destroyed 10-Dec-2015 15:04:07.365 SEVERE [http-nio-8084-exec-7] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [WebServiceTest] created a ThreadLocal with key of type [org.glassfish.gmbal.generic.OperationTracer$1] (value [org.glassfish.gmbal.generic.OperationTracer$1@2fa0bb7b]) and a value of type [java.util.ArrayList] (value [[]]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak. 10-Dec-2015 15:04:07.365 SEVERE [http-nio-8084-exec-7] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [WebServiceTest] created a ThreadLocal with key of type [com.sun.xml.bind.v2.runtime.Coordinator$1] (value [com.sun.xml.bind.v2.runtime.Coordinator$1@5b2128f3]) and a value of type [java.lang.Object[]] (value [[Ljava.lang.Object;@6a756f3a]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak. 10-Dec-2015 15:04:07.365 SEVERE [http-nio-8084-exec-7] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [WebServiceTest] created a ThreadLocal with key of type [com.sun.xml.bind.v2.ClassFactory$1] (value [com.sun.xml.bind.v2.ClassFactory$1@870b710]) and a value of type [java.util.WeakHashMap] (value [{class javax.xml.bind.annotation.W3CDomHandler=java.lang.ref.WeakReference@2221be06, class com.sun.xml.ws.runtime.config.Tubelines=java.lang.ref.WeakReference@70957c01, class javax.xml.bind.annotation.adapters.CollapsedStringAdapter=java.lang.ref.WeakReference@31d8c196, class com.sun.xml.ws.runtime.config.TubelineDefinition=java.lang.ref.WeakReference@3c1d388a, class java.util.ArrayList=java.lang.ref.WeakReference@13636081, class com.sun.xml.ws.runtime.config.TubeFactoryConfig=java.lang.ref.WeakReference@48cd7398, class com.sun.xml.ws.runtime.config.TubeFactoryList=java.lang.ref.WeakReference@3feedf66, class com.sun.xml.ws.runtime.config.MetroConfig=java.lang.ref.WeakReference@6ae27979}]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak. 10-Dec-2015 15:04:07.366 SEVERE [http-nio-8084-exec-7] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [WebServiceTest] created a ThreadLocal with key of type [org.glassfish.gmbal.generic.OperationTracer$1] (value [org.glassfish.gmbal.generic.OperationTracer$1@2fa0bb7b]) and a value of type [java.util.ArrayList] (value [[]]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak. 10-Dec-2015 15:04:07.873 INFO [http-nio-8084-exec-7] org.apache.catalina.startup.HostConfig.undeploy Undeploying context [/WebServiceTest] 10-Dec-2015 15:04:07.886 INFO [http-nio-8084-exec-5] org.apache.catalina.startup.HostConfig.deployDescriptor Deploying configuration descriptor C:\Users\logo\AppData\Roaming\NetBeans\8.1\apache-tomcat-8.0.27.0_base\conf\Catalina\localhost\WebServiceTest.xml 10-Dec-2015 15:04:09.641 INFO [http-nio-8084-exec-5] org.apache.jasper.servlet.TldScanner.scanJars At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time. 10-Dec-2015 15:04:09.653 INFO [http-nio-8084-exec-5] com.sun.xml.ws.transport.http.servlet.WSServletContextListener.contextInitialized WSSERVLET12: JAX-WS context listener initializing Hello ! 10-Dec-2015 15:04:12.505 INFO [http-nio-8084-exec-5] com.sun.xml.ws.server.MonitorBase.createRoot Metro monitoring rootname successfully set to: com.sun.metro:pp=/,type=WSEndpoint,name=/WebServiceTest-HelloService-HelloPort 10-Dec-2015 15:04:12.657 INFO [http-nio-8084-exec-5] com.sun.xml.ws.transport.http.servlet.WSServletDelegate.<init> WSSERVLET14: JAX-WS servlet initializing 10-Dec-2015 15:04:12.679 INFO [http-nio-8084-exec-5] org.apache.catalina.startup.HostConfig.deployDescriptor Deployment of configuration descriptor C:\Users\logo\AppData\Roaming\NetBeans\8.1\apache-tomcat-8.0.27.0_base\conf\Catalina\localhost\WebServiceTest.xml has finished in 4,794 ms 10-Dec-2015 15:04:12.684 INFO [http-nio-8084-exec-3] org.apache.catalina.util.LifecycleBase.start The start() method was called on component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/WebServiceTest]] after start() had already been called. The second call will be ignored. 10-Dec-2015 15:04:15.004 INFO [main] org.apache.catalina.core.StandardServer.await A valid shutdown command was received via the shutdown port. Stopping the Server instance. 10-Dec-2015 15:04:15.004 INFO [main] org.apache.coyote.AbstractProtocol.pause Pausing ProtocolHandler ["http-nio-8084"] 10-Dec-2015 15:04:15.057 INFO [main] org.apache.coyote.AbstractProtocol.pause Pausing ProtocolHandler ["ajp-nio-8009"] 10-Dec-2015 15:04:15.107 INFO [main] org.apache.catalina.core.StandardService.stopInternal Stopping service Catalina 10-Dec-2015 15:04:15.117 INFO [localhost-startStop-1] com.sun.xml.ws.transport.http.servlet.WSServletDelegate.destroy WSSERVLET15: JAX-WS servlet destroyed 10-Dec-2015 15:04:15.118 INFO [localhost-startStop-1] com.sun.xml.ws.server.MonitorBase.closeMOM Closing Metro monitoring root: com.sun.metro:pp=/,type=WSEndpoint,name=/LogoMobim-WebServices-WebServicesPort 10-Dec-2015 15:04:15.118 INFO [localhost-startStop-1] com.sun.xml.ws.transport.http.servlet.WSServletContextListener.contextDestroyed WSSERVLET13: JAX-WS context listener destroyed 10-Dec-2015 15:04:15.120 SEVERE [localhost-startStop-1] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [LogoMobim] created a ThreadLocal with key of type [com.sun.xml.bind.v2.ClassFactory$1] (value [com.sun.xml.bind.v2.ClassFactory$1@67a7ad7f]) and a value of type [java.util.WeakHashMap] (value [{class com.sun.xml.ws.runtime.config.TubeFactoryConfig=java.lang.ref.WeakReference@45471e61, class com.sun.xml.ws.runtime.config.TubeFactoryList=java.lang.ref.WeakReference@12201f93, class javax.xml.bind.annotation.W3CDomHandler=java.lang.ref.WeakReference@3f569495, class javax.xml.bind.annotation.adapters.CollapsedStringAdapter=java.lang.ref.WeakReference@65401a55, class java.util.ArrayList=java.lang.ref.WeakReference@1809b48a, class com.sun.xml.ws.runtime.config.Tubelines=java.lang.ref.WeakReference@ac7fc9f, class com.sun.xml.ws.runtime.config.TubelineDefinition=java.lang.ref.WeakReference@13e236e, class com.sun.xml.ws.runtime.config.MetroConfig=java.lang.ref.WeakReference@64c913ae}]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak. 10-Dec-2015 15:04:15.121 SEVERE [localhost-startStop-1] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [LogoMobim] created a ThreadLocal with key of type [com.sun.xml.bind.v2.runtime.Coordinator$1] (value [com.sun.xml.bind.v2.runtime.Coordinator$1@31b14659]) and a value of type [java.lang.Object[]] (value [[Ljava.lang.Object;@42767f4]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak. 10-Dec-2015 15:04:15.121 SEVERE [localhost-startStop-1] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [LogoMobim] created a ThreadLocal with key of type [org.glassfish.gmbal.generic.OperationTracer$1] (value [org.glassfish.gmbal.generic.OperationTracer$1@7472014d]) and a value of type [java.util.ArrayList] (value [[]]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak. 10-Dec-2015 15:04:15.125 INFO [localhost-startStop-1] com.sun.xml.ws.transport.http.servlet.WSServletDelegate.destroy WSSERVLET15: JAX-WS servlet destroyed 10-Dec-2015 15:04:15.126 INFO [localhost-startStop-1] com.sun.xml.ws.server.MonitorBase.closeMOM Closing Metro monitoring root: com.sun.metro:pp=/,type=WSEndpoint,name=/WebServiceTest-HelloService-HelloPort 10-Dec-2015 15:04:15.127 INFO [localhost-startStop-1] com.sun.xml.ws.transport.http.servlet.WSServletContextListener.contextDestroyed WSSERVLET13: JAX-WS context listener destroyed 10-Dec-2015 15:04:15.131 SEVERE [localhost-startStop-1] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [WebServiceTest] created a ThreadLocal with key of type [org.glassfish.gmbal.generic.OperationTracer$1] (value [org.glassfish.gmbal.generic.OperationTracer$1@31ca627c]) and a value of type [java.util.ArrayList] (value [[]]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak. 10-Dec-2015 15:04:15.136 INFO [main] org.apache.coyote.AbstractProtocol.stop Stopping ProtocolHandler ["http-nio-8084"] 10-Dec-2015 15:04:15.139 INFO [main] org.apache.coyote.AbstractProtocol.stop Stopping ProtocolHandler ["ajp-nio-8009"] 10-Dec-2015 15:04:15.153 INFO [main] org.apache.coyote.AbstractProtocol.destroy Destroying ProtocolHandler ["http-nio-8084"] 10-Dec-2015 15:04:15.154 INFO [main] org.apache.coyote.AbstractProtocol.destroy Destroying ProtocolHandler ["ajp-nio-8009"]

Notifier.notify('test')

Netbeans 8.1和Tomcat 8。

为什么它会运行两次?

1 个答案:

答案 0 :(得分:1)

在Java EE服务器环境中,实例化类的频率取决于多种因素(框架,bean的类型,bean的配置,服务器配置,用户负载......)。它不像客户端,你曾经运行过一次应用程序而且事情发生了一次。本质上,在构造函数中,您应该只执行导入以初始化对象本身的事物。

您要找的是scopes。为应用程序,会话,请求定义上下文......但是如果你需要web服务的上下文是另一种情况。

在您遇到的情况下,该类是从侦听器<load-on-startup>实例化的,并且在开始时它是从类加载器实例化的。这样做是因为在您的web.xml中有一个元素jekyll-auth,其值为&gt; = 0.

阅读有关Java EE生命周期的更多信息: