SpringBoot重启后,第一次请求接口请求慢的解决方案 |
您所在的位置:网站首页 › urandom1fd570 › SpringBoot重启后,第一次请求接口请求慢的解决方案 |
1、DispatcherServlet默认是懒加载,即工程启动的时候,Applicationcontext会将所有的bean加载到容器,但是DispatcherServlet是没有加载的,只有第一次访问的时候才会加载 场景一:DispatcherServlet懒加载情况,启动的时候如下图 场景二:spring.mvc.servlet.load-on-startup=1 DispatcherServlet关闭懒加载,启动的时候如下图: 2、随机数生成慢的原因和解决方案。Java随机数生成依赖熵源(Entropy Source),默认的阻塞型的 /dev/random熵源可能导致阻塞,而换一个非阻塞的 /dev/urandom的熵源就可以了。 解决方法: 临时、方便 以这种方式运行jar包 java -Djava.security.egd=file:/dev/./urandom -jar XXX.jar XXX 永久 进入你的JAVA_HOME的jre目录下找到并vim编辑这个文件: $JAVA_HOME/jre/lib/security/java.security 找到: securerandom.source=file:/dev/random 这一行 改之前: securerandom.source=file:/dev/random 改为: securerandom.source=file:/dev/urandom 3、进行异步处理,提高整体的响应时间 4、加入缓存,例如热点数据的预加载等,提高响应时间 5、工程启动之后,就进行一次访问 @Slf4j @Configuration public class LoadDatabase { @Bean CommandLineRunner initController(RestTemplate restTemplate) { return args -> { log.info("REQUEST " + restTemplate.execute("http://127.0.0.1:9999/t1", HttpMethod.GET, null, null)); }; } } |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |