tomcat服务重启后出现好多Exception,原来竟然是...
开发组里一小伙排查问题时,奇怪地发现tomcat服务重启后catalina.out文件中出现了好多异常。然后发wiki记录了下来。
得知此事后,我用他提供的grep命令查了一下catalina.out文件,的确存在很多包含“Exception”的日志。 再仔细看,发现都是INFO日志。再仔细看,这些语句都是 mapped ***url onto ****Controller.***method,意思是spring-mvc框架把url资源映射到action方法上。
那么,为什么有的会出现throws **Exception呢?
嘿嘿,直觉告诉了我答案。我赶紧把代码看,果然如此。
什么原因呢?很简单,是这些方法上声明了throws **Exception,见下图。所以,log里就打印出来了。
我们都知道利用方法签名来描述一个方法。方法签名通常包含可访问性、返回值、方法名、请求参数(按顺序用逗号分隔罗列各数据类型)这几个要素。看来,还包括声明的异常,即throws子句。
举个栗子,如下方法的签名是 public void pTest() throws InterruptedException 。
public void pTest() throws InterruptedException { ExecutorService pool = Executors.newFixedThreadPool(20); for (int i = 0; i < 100; i++) { pool.execute(this::foo); } pool.awaitTermination(15, TimeUnit.SECONDS); }
当然,下面方法的签名我们都知道,是 public int add(int, int)。
public int add(int a, int b) { return a + b; }
所以,看到tomcat启动日志里的这些Exception,也就不必惊慌了。下面附上这段tomcat启动日志。
信息: Initialization processed in 1278 ms
十月 25, 2021 11:07:27 下午 org.apache.catalina.core.StandardService startInternal
信息: Starting service Catalina
十月 25, 2021 11:07:27 下午 org.apache.catalina.core.StandardEngine startInternal
信息: Starting Servlet Engine: Apache Tomcat/7.0.90
....
2021-10-25 23:07:52.141 [ INFO] [] [localhost-startStop-1] [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping:182]Mapped "{[/settle/saveSettleVoucher],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public void com.yft.controller.SettleController.saveSettleVoucher(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse,org.springframework.web.multipart.MultipartFile) throws java.io.IOException
2021-10-25 23:07:52.141 [ INFO] [] [localhost-startStop-1] [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping:182]Mapped "{[/settle/downLoadVoucherImg],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.String com.yft.controller.SettleController.downLoadVoucherImg(java.lang.Long,javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse) throws java.io.IOException
2021-10-25 23:07:52.142 [ INFO] [] [localhost-startStop-1] [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping:182]Mapped "{[/settle/showDeliver],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.String com.yft.controller.SettleController.showDeliver(org.springframework.ui.ModelMap,javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
2021-10-25 23:07:52.142 [ INFO] [] [localhost-startStop-1] [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping:182]Mapped "{[/settle/downFile],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public void com.yft.controller.SettleController.downFile(java.lang.String,java.lang.String,javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse) throws java.io.IOException
2021-10-25 23:07:52.142 [ INFO] [] [localhost-startStop-1] [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping:182]Mapped "{[/validSecurityCode],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public int com.yft.controller.CodeController.validSecurityCode(javax.servlet.http.HttpServletRequest,java.lang.String)
2021-10-25 23:07:52.142 [ INFO] [] [localhost-startStop-1] [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping:182]Mapped "{[/securityCode2],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public void com.yft.controller.CodeController.getCode2(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse) throws java.io.IOException
2021-10-25 23:07:52.143 [ INFO] [] [localhost-startStop-1] [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping:182]Mapped "{[/securityCode],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public void com.yft.controller.CodeController.getCode(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse) throws java.io.IOException
2021-10-25 23:07:52.143 [ INFO] [] [localhost-startStop-1] [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping:182]Mapped "{[/invoiceRomote/romoteUpdate],methods=[POST],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.util.Map<java.lang.String, java.lang.Object> com.yft.controller.InvoiceRemoteController.updateInvoice(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse,com.yft.queryVO.InvoiceVO)
注:网上也有说,在java中,方法签名只包含方法名、请求参数。我觉得不必纠结,能消除我们的疑惑就可以了。
当看到一些不好的代码时,会发现我还算优秀;当看到优秀的代码时,也才意识到持续学习的重要!--buguge
本文来自博客园,转载请注明原文链接:https://www.cnblogs.com/buguge/p/15465662.html