Skip to main content

Posts

Showing posts from December, 2020

Multi threading in SpringBoot Application

How I got my SpringBoot application to execute a service in multiple threads Enabled SpringBoot application run Async tasks Defined a service method which can be invoked asynchronously and returns CompletableFuture object as required by Spring Let Spring manage service component instance Though not required, configured TaskExecutor Spring could use Enable SpringBoot application to run tasks asynchronously To be able to execute tasks using multiple threads asynchronously SpringBoot application must be annotated with @EnableAsync .   I defined this annotation right after   @SpringBootApplication . @SpringBootApplication @EnableAsync public class NosqlApplication implements CommandLineRunner { Logger logger = LoggerFactory. getLogger (NosqlApplication. class ) ; Aync service method returning CompletableFuture object Spring could invoke tasks synchronously and asynchronously. To be able to invoke tasks asynchronously (and let main thread do other things) I annotated the service method

Configuring Spring Framework with YAML

Spring application can be configured using YAML as effectively as using properties file. With YAML file one can, Create environment specific profiles Define properties at application level Define (or override) properties at profile level Spring Framework loads application.yml by default just the way it loads application.properties. If you want to change the name of the yml file you'll have to use context loader to tell what file to look for. Must knows of the yml based configuration Profiles - YML supports multiple profiles in a single file. One can define environment specific configurations as profiles in a single file. Profiles separator - YML configuration file uses 3 dashes ( --- ) to separate a profile. Every property you define after --- is specific to that profile. Profile name - Give profile a name using spring.config.activate.on-profile property. Active profile(s) - Define which profile or profiles are active using spring.profiles.active property. More than one profile c