Overblog Tous les blogs Top blogs Beauté, Santé & Remise en forme Tous les blogs Beauté, Santé & Remise en forme
Editer l'article Suivre ce blog Administration + Créer mon blog
MENU
http://zhsbdz.over-blog.com/

zhsbdz.over-blog.com/

Publicité

Spring Loading Delay



Spring Boot - Scheduling - Scheduling is a process of executing the tasks for the specific time period. Spring Boot provides a good support to write a scheduler on the Spring applications. This example shows you how spring load works and how it is derived from spring rate. You have a spring with a free length of 5 inches and your spring rate is of 7.5 pounds of force per inch (lbf/in). This spring needs to reach a solid height of 3 inches, therefore having to travel 2 inches. To calculate the working load of how much.

For example, a spring under a load of 300 lbs with a 109 Rate, the deflection would be calculated as follows: Deflection = 300 ÷ 109 = 2.75. Load = Deflection x Rate. For example, a spring with a 109 Rate and a 2.75' deflection, the load would be calculated as follows: Deflection.

1. Preface

Spring loading options

As our project continues to iterateBeanThe number of will be greatly increased, and it will be very time-consuming if both are initialized at startup time.Spring BootAllows delayed initialization of the application, that is, as neededSpring Bean, not in theSpring BootCreate allBean。 This will reduce the time it takes to start the application. Lazy initialization is often referred to as lazy loading.

2. Delay initialization

Spring BootThe delay initialization in can be divided intoGlobal delay initializationandLocal initialization

Note: the following features exist in spring boot 2.2. X

2.1 global initialization

Global initialization can be achieved programmatically and needs to be changedSpring Boot Main Como baixar winrar 2018. Methods.

Usually oursMainHere's how,Note that global lazy loading has not been declared

Global lazy loading method 1:

Global lazy loading method 2:

The above two methods are customized by programmingSpring BootFeatures, most of which are global. It includes 'lazy loading' described in this article.

Spring Loading Options

We can also take a simpler configuration file(application.properties)To configure delayed initialization: Change hard drive format.

When we turn on global delay loading, theWebApplications will result in manyWebdependentBeanUntil the first timeHTTPIt is not initialized until requested.

Free slots gratis sin descargar. controller

Service layer

call/reqAfter the interface, we found that not onlyFooControllerandFooServiceIn the first call to initialize, connectSpring MVCcoreDispatcherServletAre initialized on the first call.

2.2 local initialization

If we don't want global delay initialization to work on individualsBeanWhat should I do? We can do it hereBeanNotes on the statement@Lazy(value = false)That's fine. You can rewrite it2.1Try it yourself. this@LazyAct on local, and pass Boolean valuevalueTo control whether initialization is delayed. The situation is as follows:

  • When we declare a global delay load,@Lazy(value = false)MarkedBeanWill be loaded immediately.
  • When we say the big pictureNoWhen the load is delayed,@LazyMarkedBeanWill be delayed loading.
Mouse Spring Loading Delay

Please note that:@LazyWill affect@ConfigurationTheBean

3. Precautions

Spring Boot Reload Properties

The disadvantage of delayed initialization is that if theBeanIs a delayed initialization, the failure will no longer occur during startup, and only after initializationBeanErrors will only be exposed when they are exposed, so they must be strictly tested.

At the same time, care must be taken to ensure thatJVMWith enough memory to hold all applicationsBean, not just during startupBean。 Therefore, it is recommended that theJVMThe heap size is detected and fine tuned as necessary to ensure that it does not overflow.

Those initializations are time-consuming, have complex logic, and are not necessary for startupBeanShould be delayed initialized.

4. Summary

Today is rightSpring BootHow to carry out delay initialization is explained, and some precautions are also explained. IndirectlyMainSeveral postures of the method are also shown, hoping to be helpful to your actual development. Pay attention to the official account:FelordcnTechnical dry cargo data will be obtained automatically.





Publicité
Partager cet article
Repost0
Pour être informé des derniers articles, inscrivez vous :
Commenter cet article