首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >大延迟,直到SpringApplication.run()方法完成

大延迟,直到SpringApplication.run()方法完成
EN

Stack Overflow用户
提问于 2019-04-02 13:31:10
回答 1查看 120关注 0票数 0

我有以下课程:

代码语言:javascript
复制
package org.edgexfoundry.pkg;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.scheduling.annotation.EnableAsync;

@SpringBootApplication
@EnableAsync
@EnableDiscoveryClient
public class Application {
  public static ConfigurableApplicationContext ctx;

  public static void main(String[] args) {
    ctx = SpringApplication.run(Application.class, args);
    System.out.println("WELCOME!");
  }

在同一个项目的另一个班级里,我有:

代码语言:javascript
复制
@ImportResource("spring-config.xml")
public class BaseService {
    @PostConstruct
    private void postConstructInitialize() {
        logger.debug("post construction initialization");
    }
}

其中我的spring-config.xml文件是:

代码语言:javascript
复制
<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:amq="http://activemq.apache.org/schema/core" xmlns:jms="http://www.springframework.org/schema/jms"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
    xmlns:tx="http://www.springframework.org/schema/tx" xmlns:util="http://www.springframework.org/schema/util"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context.xsd">

    <context:property-placeholder
        location="classpath:*.properties" />

    <bean class="org.edgexfoundry.pkg.HeartBeat" />
    <context:component-scan base-package="org.edgexfoundry.pkg" />
    <context:component-scan base-package="org.edgexfoundry" />

</beans> 

HeartBeat类:

代码语言:javascript
复制
@EnableScheduling
public class HeartBeat {

    private static final EdgeXLogger logger = EdgeXLoggerFactory.getEdgeXLogger(HeartBeat.class);

    @Scheduled(fixedRateString = "${heart.beat.time}")
    public void pulse() {
        logger.info("Beating...");
    }
}

当我运行该项目时,我得到以下输出:

代码语言:javascript
复制
BySpringCGLIB$$1088c4ff] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
/*******************************************************************************
 * Copyright 2017, Dell, Inc.  All Rights Reserved.
 ******************************************************************************/
WELCOME!

2019-04-02 12:50:24.574  INFO 1 --- [           main] org.edgexfoundry.pkg.Application         : No active profile set, falling back to default profiles: default

经过很长一段时间,(大约8分钟),我得到最后一行:

代码语言:javascript
复制
2019-04-02 12:57:04.611 DEBUG 1 --- [           main] org.edgexfoundry.pkg.BaseService         : post construction initialization

同时又在做些什么呢?为什么@PostConstruct方法需要这么多时间来运行,即为什么SpringApplication.run()方法完成得这么晚?有什么想法吗?

EN

回答 1

Stack Overflow用户

发布于 2019-04-04 07:56:13

启动速度明显缓慢的一个原因是SecureRandom的默认实现,它扫描网络接口以提供额外的系统熵源。

可以通过注册自己的java.security.Provider或使用SecureRandomSpi来避免这种情况。

在Java中,还有关于(快速)和安全伪随机数生成的主题中的这个很好的介绍

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55476084

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档