近期将一个老项目向ARM版的CentOS7移植时,遇到了SpringBoot启动顺利,但访问页面卡住的问题。由于是aarch64架构,因此使用了openjdk,这个项目之前在x86_64环境下一直是用Oracle的ServerJRE,没有遇到问题。此次启动正常,但启动完成后,访问部分页面正常,部分页面会卡住,卡住的时间不固定,有时长有时短,毫无规律可言。而且当卡住的页面正常后,再刷新不会再次卡住。

第一想法肯定是查日志,在首次访问卡顿页面时,Spring框架有一条这样的WARN:

2019-12-09 17:40:32.995  WARN 15161 --- [https-jsse-nio-443-exec-8] o.a.c.util.SessionIdGeneratorBase        :
Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [178,241] milliseconds.

为Session创建SecureRandom实例耗时将近3分钟,这就是页面卡住的原因,同时也解释了为什么只有部分页面卡住,因为不是所有页面都使用了Session,同时也解析了为什么卡住的页面可访问后再刷新就正常了,因为创建SecureRandom instance只进行一次。2019-12-09 17:40:32.995  WARN 15161 --- [https-jsse-nio-443-exec-8] o.a.c.util.SessionIdGeneratorBase        : Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [178,241] milliseconds.

翻回来看看原因,项目中使用了Tomcat Embed作为内嵌WEB服务器,而Tomcat在生成session ID时会使用org.apache.catalina.util.SessionIdGeneratorBase来产生安全随机类SecureRandom实例。为了算法保密性较强,需要用到伪随机数生成器,Tomcat用到的是SHA1PRNG算法,为了得到随机种子,在Linux中,一般从/dev/random或/dev/urandom中产生,两者原理都是利用系统的环境噪声产生一定数量的随机比特,区别在于系统环境噪声不够时,random会阻塞,而urandom会牺牲安全性避免阻塞。

从卡顿现象上看,一定是用了/dev/random导致的,看一下$JAVA_HOME/jre/lib/security/java.security文件,找到下面的内容:

#
# Sun Provider SecureRandom seed source.
#
# Select the primary source of seed data for the "SHA1PRNG" and
# "NativePRNG" SecureRandom implementations in the "Sun" provider.
# (Other SecureRandom implementations might also use this property.)
#
# On Unix-like systems (for example, Solaris/Linux/MacOS), the
# "NativePRNG" and "SHA1PRNG" implementations obtains seed data from
# special device files such as file:/dev/random.
#
# On Windows systems, specifying the URLs "file:/dev/random" or
# "file:/dev/urandom" will enable the native Microsoft CryptoAPI seeding
# mechanism for SHA1PRNG.
#
# By default, an attempt is made to use the entropy gathering device
# specified by the "securerandom.source" Security property. If an
# exception occurs while accessing the specified URL:
#
# SHA1PRNG:
# the traditional system/thread activity algorithm will be used.
#
# NativePRNG:
# a default value of /dev/random will be used. If neither
# are available, the implementation will be disabled.
# "file" is the only currently supported protocol type.
#
# The entropy gathering device can also be specified with the System
# property "java.security.egd". For example:
#
# % java -Djava.security.egd=file:/dev/random MainClass
#
# Specifying this System property will override the
# "securerandom.source" Security property.
#
# In addition, if "file:/dev/random" or "file:/dev/urandom" is
# specified, the "NativePRNG" implementation will be more preferred than
# SHA1PRNG in the Sun provider.
#
securerandom.source=file:/dev/random

果然用的是/dev/random,按照上面的注释部分,解决方案也不复杂,可以添加启动参数或者修改java.security:

解决方法1:
启动参数添加-Djava.security.egd=file:/dev/urandom,如:

java -Djava.security.egd=file:/dev/urandom -jar xxxxx.jar

解决方法2:

修改$JAVA_HOME/jre/lib/security/java.security,找到securerandom.source并修改:

securerandom.source=file:/dev/urandom

再重启站点,卡顿现象消失。

OpenJDK下SpringBoot使用HttpSession时页面打开卡住的更多相关文章

  1. IE6,IE7文档模式下 按钮type=submit在页面打开时会有一条黑线边框的处理方法。(转)

    一:按钮border:none:同时使用背景图片来实现border效果. 二:在按钮外面嵌套一层label标签,里面的按钮input[type="submit"]的border:n ...

  2. Tomcat 程序无问题的情况下页面打开变慢的原因

    看看这写日志的频率就知道我有多闲了.. 前言: 其实关于tomcat,遇到过很多关于“慢”的问题,比如启动慢,比如页面打开慢, 以前太忙也太懒,不愿意花时间分析原因,现在终于肯静下来找原因 环境是ec ...

  3. 使EditText不要在页面打开时自动获取焦点(因为软键盘会自动弹出)

    当页面上有EditText时,第一个EditText会在页面打开时自动的获取焦点,这样带来的问题就是系统键盘会自动的弹出来. 解决方法比较简单只要为EditText的父控件设置一下就行了: andro ...

  4. 解决HTML加载时,外部js文件引用较多,影响页面打开速度问题

    解决HTML加载时,外部js文件引用较多,影响页面打开速度问题   通常HTML文件在浏览器中加载时,浏览器都会按照<script>元素在页面中出现的先后顺序,对它们依次加载,一旦加载的j ...

  5. springboot整合html时的页面的跳转404

    在用springboot对html的页面进行渲染时,页面找不到报404(type=Not Found, status=404)., 解决办法:是在ctroller层加相应的           @Re ...

  6. 解决加载WEB页面时,由于JS文件引用过多影响页面打开速度的问题

    1.一般做法 一般我们会把所有的<script>元素都应该放在页面的<head>标签里,但由于是顺序加载,因此只有当所有JavaScript代码都被依次下载.解析和执行完之后, ...

  7. 【spring boot】idea下springboot打包成jar包和war包,并且可以在外部tomcat下运行访问到(转)

    转自:https://www.cnblogs.com/sxdcgaq8080/p/7727249.html   接着上一章走呗:http://www.cnblogs.com/sxdcgaq8080/p ...

  8. 【spring boot】6.idea下springboot打包成jar包和war包,并且可以在外部tomcat下运行访问到

    接着上一章走呗:http://www.cnblogs.com/sxdcgaq8080/p/7712874.html 然后声明一点,下面打包的过程中,scope一直都是使用默认的范围 <!--用于 ...

  9. idea下springboot打包成jar包和war包,并且可以在外部tomcat下运行访问到

    接着上一章走呗:http://www.cnblogs.com/sxdcgaq8080/p/7712874.html 然后声明一点,下面打包的过程中,scope一直都是使用默认的范围 <!--用于 ...

随机推荐

  1. [20190510]rman备份的疑问8.txt

    [20190510]rman备份的疑问8.txt --//上午测试rman备份多个文件,探究input memory buffer 的问题.--//补充测试5个文件的情况.--//http://blo ...

  2. Day_02

    1.无参数无返回值函数的使用 package main import "fmt" //无参无返回值函数的定义 func MyFunc() { a := 666 fmt.Printl ...

  3. 关于tomcat setenv

    tomcat setenv首先寻找执行base下的若不存在,寻找home下的只会执行一个

  4. 6.2 DataFrame

    一.DataFrame概述 在Spark SQL中,DataFrame就是它的数据抽象,对DataFrame进行转换操作. DataFrame的推出,让Spark具备了处理大规模结构化数据的能力,不仅 ...

  5. vue 组件之纯表格渲染--没有事件交互

    组件 名称小写==> 用-链接 02===> 属性==> empty-text="暂无数据" 当表格中没有数据 就会显示 暂无数据 <el-table-co ...

  6. fiddler设置https抓包

    代理端口设置:127.0.0.1:8888 https抓包设置 模拟post请求: http://xxx.xxxx.com/portal/login.htm Cookie: xxxx account= ...

  7. matlib调用python时转py格式为matlib格式

    因为需要,我用matlib调用python代码. 调用成功但是遇到问题 如下 调用完的结果为python格式   (py.list,py.xx) matlib根本不能用 查了半天一个能解决的方法都没 ...

  8. 【2019.7.22 NOIP模拟赛 T1】麦克斯韦妖(demon)(质因数分解+DP)

    暴力\(DP\) 先考虑暴力\(DP\)该怎么写. 因为每个序列之后是否能加上新的节点只与其结尾有关,因此我们设\(f_i\)为以\(i\)为结尾的最长序列长度. 每次枚举一个前置状态,判断是否合法之 ...

  9. spring cloud 与spring boot 版本不匹配引发的问题总结

    为了将前期项目慢慢转移到微服务上,今天开始搭建eureka服务时,出现以下错误: org.springframework.context.ApplicationContextException: Un ...

  10. 物联网架构成长之路(40)-Bladex开发框架入门

    0. 前言 前一小节,讲了如何入门,这里就简单讲一下如何自定义查询和权限控制配置. 1. 配置多租户 如果要启用该表的多租户功能,需要在application.yml 这里配置. 2. 配置模糊匹配 ...