1、环境
tomcat6.0.8 + jdk6 + struts1
2、问题的产生
页面有两个异常的请求
http://127.0.0.1/project/a.action?do=testA&m=10
http://127.0.0.1/project/a.action?do=testB&m=10
两个请求几乎同步到达server。结果出现异常:
java.lang.NullPointerException
at org.apache.catalina.connector.Request.parseParameters(Request.java:2446)
at org.apache.catalina.connector.Request.getParameter(Request.java:1040)
at org.apache.catalina.connector.RequestFacade.getParameter(RequestFacade.java:355)
at com.tepper.common.util.JsonUtil.jsonResponse(JsonUtil.java:101)
at com.tepper.flow.action.TechnologyFlowAction.loadLinkers(TechnologyFlowAction.java:126)
at com.tepper.flow.action.TechnologyFlowAction.judgeRequest(TechnologyFlowAction.java:86)
at com.tepper.flow.action.TechnologyFlowAction.execute(TechnologyFlowAction.java:59)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:419)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:224)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.tepper.common.SessionFilter.doFilter(SessionFilter.java:76)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.tepper.common.ResFilter.doFilter(ResFilter.java:49)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:433)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:619)
或者后台没异常,前台第一个请求的response返回的是第二个请求的结果。而第二次请求则没有response。
经调试,发现两次请求的request对象是同一对象。然后想起Struts1是非线程安全的,而我在代码中,为了让一个Action接收多个页面的请求,把request对象写成了全局对象。
3、解决
struts1是非线程安全的。两个同一时间的异步请求,会得到同一个request对象,两个请求会造成冲突。
在execution方法中使用局部变量是最简单的保证线程安全的方法了。也就是说在使用struts1的action时,不要在类中定义属性。
把全局的request对象,放回execution方法中,变成局部变量,问题得到解决。
分享到:
相关推荐
问题1:TOMCAT下载文件出错:org.apache.catalina.connector.ClientAbortException. 问题2:TOMCAT记录接收数据大小、发送数据大小和请求处理时间
org.apache.catalina.core.AprLifecycleListener myeclipse tomcat 無法啟動 用這個文件
2010-8-11 18:24:13 org.apache.catalina.core.AprLifecycleListener lifecycleEvent 信息: The Apache Tomcat Native library which allows optimal performance in production environments was not found on the ...
3月 17, 2019 10:51:41 上午 org.apache.catalina.startup.VersionLoggerListener log 信息: Server version: Apache Tomcat/7.0.78 3月 17, 2019 10:51:41 上午 org.apache.catalina.startup.VersionLoggerListener...
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342) at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:803) at org.apache.coyote....
apache-tomcat软件,windows-64版本 日志可查看catalina.out,如下: at org.springframework.web.servlet.mvc.method.annotation... at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:261) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844) at org.apache.coyote....
在 Linux 下,可以在 `catalina.sh` 文件中添加 `export JAVA_OPTS="-server -Xms512m -Xmx1024m"`,以设置 JVM 的堆大小。 优化程序 1. 避免死循环:检查程序中是否存在死循环,并进行优化。 2. 手动回收垃圾:...
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:875) at org.apache.coyote....
at org.apache.catalina.startup.Catalina.start(Catalina.java:578) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl....
jar包,官方版本,自测可用
- 对于Tomcat服务器,可以在`catalina.bat`(Windows)或`catalina.sh`(Linux)中设置: ``` set JAVA_OPTS=%JAVA_OPTS% -Xms128m -Xmx512m ``` 2. **优化代码**: - 检查是否存在内存泄露,例如循环引用等。...
2011-1-8 20:34:20 org.apache.catalina.core.StandardWrapperValve invoke 严重: Servlet.service() for servlet default threw exception java.lang.IllegalStateException at org.apache.catalina.connector....
这个过程由Apache Tomcat服务器执行,一个流行的Java Servlet容器。然而,部署过程中遇到了问题,特别是与`blog`应用程序相关的错误。 错误发生在尝试配置应用程序监听器时,监听器类为`org.springframework.web....
严重 [RMI TCP Connection(3)-127.0.0.1] org.apache.catalina.core.StandardContext.startInternal Error-附件资源
jar包,官方版本,自测可用
nginx过滤器不推荐使用 org.apache.catalina.valves.RemoteIpValve 代替。 此项目将永远不会再更新。 ============ java web应用的过滤器,通常可以配置全局服务器。 <filter> <filter>NginxFilter</filter> ...
org.apache.catalina org.apache.commons org.apache.coyote org.apache.ibatis org.apache.juli 4号包: org.apache.tiles org.apache.velocity org.apache.xerces org.apache.xml org.apache.xmlbeans org.apache....