Skip to main content

Posts

Showing posts from April, 2022

Quartz Scheduler with SpringBoot

In the previous post,  Quartz Scheduler Introduction  we learned the basics of the Quartz subsystem with plain java. In this post, We will use spring boot magic to create an application with Quartz. This application will have the following. An endpoint, to show current items in the system. A quartz job, to keep adding a new item at a regular interval. Before we start with quartz, let's do some basic SpringBoot setup 1. Maven Project: Create a maven project the way you like, Either by using your favorite IDE or by command line or by  spring-starter .   just keep the name of your project as  QuartzSpringApplication  If you do not want to modify any code provided in this article After that add the following dependencies in your pom.xml.  Lombok  is not needed, but I like to use it everywhere. <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-webflux</artifactId> </dependency> <dependency>

Coding with Java Optionals!

In the previous blog  NullPointerException to Optional!  , we discussed how Optional came to the world. In this blog, let’s look at its usage/misusage. Optional has been a very controversial java-type Not just the incorrect use, often times you see a lot of unnecessary usage and silent nulls. Optional<T>  indicates the presence or absence of a value of type  T .  The  java.util.Optional  class is decorated with 3  static  factory methods. Any of these can be used to create an instance of Optional. public static <T> Optional<T> empty () public static <T> Optional<T> of (T value) public static <T> Optional<T> ofNullable(T value) Once you have the instance, the following are some (not all) significant methods available for use public T get () public boolean isPresent () public void ifPresent (Consumer<? super T> consumer) public Optional<T> filter (Predicate<? super T> predicate) <U>