java war启动慢_解决springboot war包在tomcat部署时启动慢的问题

文章详细介绍了如何解决SpringBoot WAR包在Tomcat部署时启动慢的问题,包括修改JDK的Java.security文件以加速随机数生成,解决MySQL SSL连接验证问题,以及禁用Springboot的JNDI功能来减少不必要的查找操作,从而显著提升启动速度。
摘要由CSDN通过智能技术生成

b16ae3a83ccf?from=singlemessage

web.jpg

最近测试服务器tomcat发布一次很慢,为了解决这个问题,特地看了tomcat的log文件,启动日志在tomcat/logs/catalina.out文件中。

1、INFO:org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory xxx.war卡顿

刺风同学就是好记性不如烂笔头的实践者,被我也用上了。

找到jdk1.x.x_xx/jre/lib/security/Java.security文件,在文件中找到securerandom.source这个设置项,将其改为:

securerandom.source=file:/dev/./urandom

重启tomcat,这一步的速度明显加快。

原理据说是这样的:

linux或者部分unix系统提供随机数设备是/dev/random 和/dev/urandom ,

两个有区别,urandom安全性没有random高,但random需要时间间隔生成随机数。jdk默认调用random。

2、 WARN: Establishing SSL connection without server's identity verification is not recommended.

具体错误是这样的:

Mon Jul 09 09:30:13 CST 2018 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.

Mon Jul 09 09:30:13 CST 2018 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.

Mon Jul 09 09:30:14 CST 2018 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.

这个错误会打几遍,每一遍都会卡一会儿,应该是在验证mysql的SSL配置。

查阅资料说mysql的高版本默认要求使用SSL链接,所以在没有配置SSL也没有说SSL不需要时,就会一直验证,验证好几遍以后放弃。

这个时间大概有1分钟。

当然,方案就是在jdbc的链接上加上userSSL=false这个参数,

jdbc:p6spy:mysql://127.0.0.1:3306/chuangke?characterEncoding=utf-8&useSSL=false&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=Hongkong&autoReconnect=true

类似这样。

3、 禁用Springboot的JNDI功能

原来的log

10:40:24.103 [localhost-startStop-1] DEBUG org.springframework.web.context.support.StandardServletEnvironment - Replacing PropertySource 'servletContextInitParams' with 'servletContextInitParams'

10:40:24.685 [localhost-startStop-1] DEBUG org.springframework.jndi.JndiTemplate - Looking up JNDI object with name [java:comp/env/logging.exception-conversion-word]

10:40:24.686 [localhost-startStop-1] DEBUG org.springframework.jndi.JndiLocatorDelegate - Converted JNDI name [java:comp/env/logging.exception-conversion-word] not found - trying original name [logging.exception-conversion-word]. javax.naming.NameNotFo

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值