Tomcat启动时SecureRandom非常慢解决办法

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/gianttj/article/details/84878131

根本原因是 SecureRandom 这个 jre 的工具类的问题。那为什么 SecureRandom generateSeed 这么慢,甚至挂在 Linux 操作系统呢?

Tomcat 7/8 都使用 org.apache.catalina.util.SessionIdGeneratorBase.createSecureRandom 类产生安全随机类 SecureRandom 的实例作为会话 ID。

Tomcat 使用 SHA1PRNG 算法是基于 SHA-1 算法实现且保密性较强的伪随机数生成器。

在 SHA1PRNG 中,有一个种子产生器,它根据配置执行各种操作。

Linux 中的随机数可以从两个特殊的文件中产生,一个是 /dev/urandom,另外一个是 /dev/random。他们产生随机数的原理是利用当前系统的熵池来计算出固定一定数量的随机比特,然后将这些比特作为字节流返回。熵池就是当前系统的环境噪音,熵指的是一个系统的混乱程度,系统噪音可以通过很多参数来评估,如内存的使用,文件的使用量,不同类型的进程数量等等。如果当前环境噪音变化的不是很剧烈或者当前环境噪音很小,比如刚开机的时候,而当前需要大量的随机比特,这时产生的随机数的随机效果就不是很好了。

这就是为什么会有 /dev/urandom 和 /dev/random 这两种不同的文件,后者在不能产生新的随机数时会阻塞程序,而前者不会(ublock),当然产生的随机数效果就不太好了,这对加密解密这样的应用来说就不是一种很好的选择。/dev/random 会阻塞当前的程序,直到根据熵池产生新的随机字节之后才返回,所以使用 /dev/random 比使用 /dev/urandom 产生大量随机数的速度要慢。

SecureRandom generateSeed  使用 /dev/random 生成种子。但是 /dev/random 是一个阻塞数字生成器,如果它没有足够的随机数据提供,它就一直等,这迫使 JVM 等待。键盘和鼠标输入以及磁盘活动可以产生所需的随机性或熵。但在一个服务器缺乏这样的活动,可能会出现问题。

有2种解决方案:

1. 在Tomcat环境中解决:

可以通过配置 JRE 使用非阻塞的 Entropy Source:

在 catalina.sh 中加入这么一行:-Djava.security.egd=file:/dev/urandom 即可。

2. 在 JVM 环境中解决:

打开 $JAVA_PATH/jre/lib/security/java.security 这个文件,找到下面的内容:

1
securerandom.source=file:/dev/random

替换成:

1
securerandom.source=file:/dev/urandom
展开阅读全文
博主设置当前文章不允许评论。

tomcat启动时非常慢,麻烦帮忙看看原因,指点下

10-11

我的TOMCAT启动时总在一个地方要停留一分半钟左右,然后就报:rnfile IO Exception:java.io.IOException: 数据错误(循环冗余检查)。rn错误输出出来后,继续正常运行,直到正常启动完毕,里面的工程启动一切正常,也能正常运行,但就时每次启动到上面那个地方要等待100秒左右,很是烦人,有谁知道是什么原因么,望告知下:里面的工程无论是在我的机子还是他人的环境下都能正常运行,但就是在这个地方要出现停留现象:控制台输出如下:rn2008-10-11 16:04:14 org.apache.coyote.http11.Http11Protocol initrn信息: Initializing Coyote HTTP/1.1 on http-8080rn2008-10-11 16:04:15 org.apache.catalina.startup.Catalina loadrn信息: Initialization processed in 3345 msrn2008-10-11 16:04:15 org.apache.catalina.core.StandardService startrn信息: Starting service Catalinarn2008-10-11 16:04:15 org.apache.catalina.core.StandardEngine startrn信息: Starting Servlet Engine: Apache Tomcat/5.0.28rn2008-10-11 16:04:15 org.apache.catalina.core.StandardHost startrn信息: XML validation disabledrn2008-10-11 16:04:15 org.apache.catalina.core.StandardHost getDeployerrn信息: Create Host deployer for direct deployment ( non-jmx ) rn2008-10-11 16:04:15 org.apache.catalina.core.StandardHostDeployer installrn信息: Processing Context configuration file URL file:D:\Tomcat\conf\Catalina\localhost\admin.xmlrn2008-10-11 16:04:17 org.apache.struts.util.PropertyMessageResources rn信息: Initializing, config='org.apache.struts.util.LocalStrings', returnNull=truern2008-10-11 16:04:17 org.apache.struts.util.PropertyMessageResources rn信息: Initializing, config='org.apache.struts.action.ActionResources', returnNull=truern2008-10-11 16:04:18 org.apache.struts.util.PropertyMessageResources rn信息: Initializing, config='org.apache.webapp.admin.ApplicationResources', returnNull=truern[color=#FF0000]file IO Exception:java.io.IOException: 数据错误(循环冗余检查)。[/color]rn2008-10-11 16:05:55 org.apache.catalina.core.StandardHostDeployer installrn信息: Processing Context configuration file URL file:D:\Tomcat\conf\Catalina\localhost\manager.xmlrn2008-10-11 16:05:55 org.apache.catalina.core.StandardHostDeployer installrn信息: Installing web application at context path /cos from URL file:D:\Tomcat\webapps\cosrn2008-10-11 16:05:59 org.apache.catalina.loader.WebappClassLoader validateJarFilern信息: validateJarFile(D:\Tomcat\webapps\cos\WEB-INF\lib\servlet-api.jar) - jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending class: javax/servlet/Servlet.classrn2008-10-11 16:06:00 org.apache.myfaces.config.FacesConfigurator feedStandardConfigrn信息: Reading standard config org/apache/myfaces/resource/standard-faces-config.xmlrn2008-10-11 16:06:01 org.apache.myfaces.config.FacesConfigurator feedClassloaderConfigurationsrn信息: Reading config jar:file:/D:/Tomcat/webapps/cos/WEB-INF/lib/adf-faces-impl.jar!/META-INF/faces-config.xmlrn2008-10-11 16:06:01 org.apache.myfaces.config.FacesConfigurator feedClassloaderConfigurationsrn信息: Reading config jar:file:/D:/Tomcat/webapps/cos/WEB-INF/lib/afc.jar!/META-INF/faces-config.xmlrn2008-10-11 16:06:01 org.apache.myfaces.config.FacesConfigurator feedClassloaderConfigurationsrn信息: Reading config jar:file:/D:/Tomcat/webapps/cos/WEB-INF/lib/sandbox.jar!/META-INF/faces-config.xmlrn2008-10-11 16:06:01 org.apache.myfaces.config.FacesConfigurator feedClassloaderConfigurationsrn信息: Reading config jar:file:/D:/Tomcat/webapps/cos/WEB-INF/lib/tomahawk.jar!/META-INF/faces-config.xmlrn2008-10-11 16:06:01 org.apache.myfaces.config.FacesConfigurator feedContextSpecifiedConfigrn信息: Reading config /WEB-INF/config/faces-config.xmlrn2008-10-11 16:06:02 org.apache.myfaces.config.FacesConfigurator feedContextSpecifiedConfigrn信息: Reading config /WEB-INF/config/faces-config-FND.xmlrn2008-10-11 16:06:02 org.apache.myfaces.config.FacesConfigurator feedContextSpecifiedConfigrn信息: Reading config /WEB-INF/config/faces-config-HQFS.xmlrn2008-10-11 16:06:02 org.apache.myfaces.config.FacesConfigurator feedContextSpecifiedConfigrn信息: Reading config /WEB-INF/config/faces-config-QUERY.xmlrn2008-10-11 16:06:02 org.apache.myfaces.config.FacesConfigurator feedContextSpecifiedConfigrn信息: Reading config /WEB-INF/config/faces-config-LOG.xmlrn2008-10-11 16:06:08 org.apache.myfaces.webapp.StartupServletContextListener initFacesrn信息: ServletContext 'D:\Tomcat\webapps\cos\' initialized.rn2008-10-11 16:06:08 org.springframework.web.context.ContextLoader initWebApplicationContextrn信息: Root WebApplicationContext: initialization startedrn2008-10-11 16:06:08 org.springframework.core.CollectionFactory rn信息: JDK 1.4+ collections availablern2008-10-11 16:06:08 org.springframework.core.CollectionFactory rn信息: Commons Collections 3.x available 论坛

Tomcat启动加载非常慢,求指导

05-01

最近突然发现tomcat启动时非常慢,应用还没启动已经耗时40多秒,从日志中看,加粗部分耗时最严重,但不知道这段时间在做什么?求大神指导优化rn五月 01, 2018 11:11:06 上午 org.apache.tomcat.util.digester.SetPropertiesRule beginrn警告: [SetPropertiesRule]Server/Service/Engine/Host/Context Setting property 'source' to 'org.eclipse.jst.jee.server:sense-web' did not find a matching property.rn五月 01, 2018 11:11:06 上午 org.apache.catalina.startup.VersionLoggerListener logrn信息: Server version: Apache Tomcat/8.0.51rn五月 01, 2018 11:11:06 上午 org.apache.catalina.startup.VersionLoggerListener logrn信息: Server built: Apr 9 2018 21:20:15 UTCrn五月 01, 2018 11:11:06 上午 org.apache.catalina.startup.VersionLoggerListener logrn信息: Server number: 8.0.51.0rn五月 01, 2018 11:11:06 上午 org.apache.catalina.startup.VersionLoggerListener logrn信息: OS Name: Windows 8.1rn五月 01, 2018 11:11:06 上午 org.apache.catalina.startup.VersionLoggerListener logrn信息: OS Version: 6.3rn五月 01, 2018 11:11:06 上午 org.apache.catalina.startup.VersionLoggerListener logrn信息: Architecture: x86rn五月 01, 2018 11:11:06 上午 org.apache.catalina.startup.VersionLoggerListener logrn信息: Java Home: C:\Program Files\java\jdk1.7.0_60\jrern五月 01, 2018 11:11:06 上午 org.apache.catalina.startup.VersionLoggerListener logrn信息: JVM Version: 1.7.0_60-b19rn五月 01, 2018 11:11:06 上午 org.apache.catalina.startup.VersionLoggerListener logrn信息: JVM Vendor: Oracle Corporationrn五月 01, 2018 11:11:06 上午 org.apache.catalina.startup.VersionLoggerListener logrn信息: CATALINA_BASE: D:\Workspaces\MavenWorkspaces\.metadata\.plugins\org.eclipse.wst.server.core\tmp0rn五月 01, 2018 11:11:06 上午 org.apache.catalina.startup.VersionLoggerListener logrn信息: CATALINA_HOME: E:\Tomcat\apache-tomcat-8.0.51rn五月 01, 2018 11:11:06 上午 org.apache.catalina.startup.VersionLoggerListener logrn信息: Command line argument: -agentlib:jdwp=transport=dt_socket,suspend=y,address=localhost:50065rn五月 01, 2018 11:11:06 上午 org.apache.catalina.startup.VersionLoggerListener logrn信息: Command line argument: -Xms512mrn五月 01, 2018 11:11:06 上午 org.apache.catalina.startup.VersionLoggerListener logrn信息: Command line argument: -Xmx512mrn五月 01, 2018 11:11:06 上午 org.apache.catalina.startup.VersionLoggerListener logrn信息: Command line argument: -XX:PermSize=256Mrn五月 01, 2018 11:11:06 上午 org.apache.catalina.startup.VersionLoggerListener logrn信息: Command line argument: -XX:MaxPermSize=512Mrn五月 01, 2018 11:11:06 上午 org.apache.catalina.startup.VersionLoggerListener logrn信息: Command line argument: -Dcatalina.base=D:\Workspaces\MavenWorkspaces\.metadata\.plugins\org.eclipse.wst.server.core\tmp0rn五月 01, 2018 11:11:06 上午 org.apache.catalina.startup.VersionLoggerListener logrn信息: Command line argument: -Dcatalina.home=E:\Tomcat\apache-tomcat-8.0.51rn五月 01, 2018 11:11:06 上午 org.apache.catalina.startup.VersionLoggerListener logrn信息: Command line argument: -Dwtp.deploy=D:\Workspaces\MavenWorkspaces\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebappsrn五月 01, 2018 11:11:06 上午 org.apache.catalina.startup.VersionLoggerListener logrn信息: Command line argument: -Djava.endorsed.dirs=E:\Tomcat\apache-tomcat-8.0.51\endorsedrn五月 01, 2018 11:11:06 上午 org.apache.catalina.startup.VersionLoggerListener logrn信息: Command line argument: -Dfile.encoding=UTF-8rn五月 01, 2018 11:11:06 上午 org.apache.catalina.core.AprLifecycleListener lifecycleEventrn信息: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\java\jdk1.7.0_60\bin;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\Program Files\java\jdk1.7.0_60\jre\bin;C:/Program Files/java/jdk1.8/bin/../jre/bin/client;C:/Program Files/java/jdk1.8/bin/../jre/bin;C:/Program Files/java/jdk1.8/bin/../jre/lib/i386;C:\Program Files (x86)\Common Files\NetSarang;D:\oracle\oracle11g\product\11.2.0\dbhome_1\bin;D:\oracle\product\10.2.0\client_1;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\Program Files\java\jdk1.7.0_60\bin;C:\Program Files\TortoiseSVN\bin;C:\Program Files (x86)\MySQL\MySQL Server 5.1\bin;C:\Users\zhangqsg.DIGITALCHINA\AppData\Local\Microsoft\WindowsApps;C:\Program Files\java\ant-1.9.6\bin;C:\Program Files\java\apache-maven-3.5.0\bin;D:\Program Files\Fiddler2;D:\Program Files\eclipse;;.rn五月 01, 2018 11:11:07 上午 org.apache.coyote.AbstractProtocol initrn信息: Initializing ProtocolHandler ["http-nio-9001"]rn五月 01, 2018 11:11:07 上午 org.apache.tomcat.util.net.NioSelectorPool getSharedSelectorrn信息: Using a shared selector for servlet write/readrn五月 01, 2018 11:11:07 上午 org.apache.coyote.AbstractProtocol initrn信息: Initializing ProtocolHandler ["ajp-nio-9009"]rn五月 01, 2018 11:11:07 上午 org.apache.tomcat.util.net.NioSelectorPool getSharedSelectorrn信息: Using a shared selector for servlet write/readrn五月 01, 2018 11:11:07 上午 org.apache.catalina.startup.Catalina loadrn信息: Initialization processed in 1952 msrn五月 01, 2018 11:11:07 上午 org.apache.catalina.core.StandardService startInternalrn信息: Starting service Catalinarn五月 01, 2018 11:11:07 上午 org.apache.catalina.core.StandardEngine startInternalrn信息: Starting Servlet Engine: Apache Tomcat/8.0.51rn[b]五月 01, 2018 11:11:09 上午 org.apache.catalina.util.SessionIdGeneratorBase createSecureRandomrn警告: Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [996] milliseconds.rn五月 01, 2018 11:11:51 上午 org.apache.jasper.servlet.TldScanner scanJars[/b][color=#FF0000][/color]rn信息: 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.rn五月 01, 2018 11:11:51 上午 org.apache.catalina.core.ApplicationContext logrn信息: No Spring WebApplicationInitializer types detected on classpathrn五月 01, 2018 11:11:51 上午 org.apache.catalina.core.ApplicationContext logrn信息: Set web app root system property: 'SmartSense' = [D:\Workspaces\MavenWorkspaces\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\sense-web\]rn五月 01, 2018 11:11:52 上午 org.apache.catalina.core.ApplicationContext logrn信息: Initializing log4j from [classpath:log4j.properties]rn五月 01, 2018 11:11:52 上午 org.apache.catalina.core.ApplicationContext logrn信息: Initializing Spring root WebApplicationContext 论坛

项目运行非常

04-24

这是我的一段登录提交代码,帮我看看,是哪里不好么,怎么发布到iis上后就非常之缓慢了?rnrnrnrn//提交按钮rnprotected void btnSubmit_Click(object sender, EventArgs e)rn rn string id = txtId.Text;rn string password = txtPassword.Text;rn if (id.Equals(""))rn rn Response.Write(" ");rn return;rn rn if (password.Equals(""))rn rn Response.Write(" ");rn return;rn rn User user = UserManager.GetUserById(id);rn if (user==null)rn rn Response.Write(" ");rn return;rn rn if (!user.Password.Equals(password))rn rn Response.Write(" ");rn return;rn rn Session["loginUser"] = user;rn Response.Redirect("Index.aspx");rn rnrnrnrnrnrn/// rn /// 根据编号获取系统用户信息 rn /// rn /// 编号 rn /// 系统用户信息 rn public static User GetUserById(string id) rn rn sqlQuery = "select * from [user] where State = 1 and Id='" + id + "'"; rn User user = null; rn SqlDataReader reader = DBHelper.GetReader(sqlQuery); rn try rn rn if (reader.Read()) rn rn user = new User(); rn user.Id = reader["Id"].ToString(); rn user.Name = reader["Name"].ToString(); rn user.Password = reader["Password"].ToString(); rn user.Email = reader["Email"].ToString(); rn user.Post = PostService.GetPostById(Convert.ToInt32(reader["PostId"].ToString())); rn user.BeginDate = Convert.ToDateTime(reader["BeginDate"].ToString()); rn user.Superior = reader["Superior"].ToString(); rn user.Level = Convert.ToInt32(reader["Level"].ToString()); rn user.Vacation = Convert.ToDouble(reader["Vacation"].ToString()); rn user.State = Convert.ToInt32(reader["State"].ToString()); rn rn rn catch (Exception ex) rn rn Console.WriteLine(ex.Message); rn rn finally rn rn if (reader != null) rn rn reader.Dispose(); rn rn rn return user; rn rnrnprivate static SqlConnection connection;//数据库连接rn private static string str = ConfigurationManager.ConnectionStrings["conMaster"].ConnectionString;rn /// rn /// 数据库连接rn /// rn public static SqlConnection Connectionrn rn getrn rn string strcon = ConfigurationManager.ConnectionStrings["conString"].ConnectionString;rn DBHelper.connection = null;rn //string strcon = "server=allen-pc;uid=sa;pwd=;database=OADB";rn if (connection == null)rn rn connection = new SqlConnection(strcon);rn connection.Open();rn rn if (connection.State == ConnectionState.Broken)rn rn connection.Close();rn connection.Open();rn rn if (connection.State == ConnectionState.Closed)rn rn connection.Open();rn rn return DBHelper.connection;rn rn rnrnrn/// rn /// 执行查询,返回Reader对象rn /// rn /// rn /// rn /// rn public static SqlDataReader GetReader(string sqlQuery, params SqlParameter[] values)rn rn SqlDataReader dr = null;rn tryrn rn SqlCommand command = new SqlCommand(sqlQuery, Connection);rn command.Parameters.AddRange(values);rn dr = command.ExecuteReader();rn rn catch (Exception ex)rn rn Console.WriteLine(ex.Message);rn rn return dr;rn rn 论坛

没有更多推荐了,返回首页