Java Static vs Dynamic Casting

Every time I needed to cast objects in Java I always thought dynamic casting, using Class.cast() was more expensive than simply using the (cast) operator. But apparently in Java, static vs dynamic casting don’t mean much difference. Let’s consider this code. And a class that implements my interface. Now I’ll create a situation that requires … Read more

Cancel @Async Thread in Spring Boot

Before going to the cancel async example, please quickly check these two short articles because it might give you a better overview of what I’m saying. Stop thread execution Control thread using exceptions Premise: You have a Spring Boot app that needs to execute a long running task. You don’t want to have the user … Read more

Enum with Different Behavior in Java

You sometimes need an enum with different behavior in Java. Consider the following case where you have an employee management application. It displays information about all the company’s employees. In your application settings you want to configure how many fields you want to see. For example you might not care about the employee’s date of … Read more

Java Cache Service using Spring

We’ll now create a simple yet effective Java cache service using Spring Boot. A cache service is useful to leverage load on the database, especially if multiple users are querying for information and specifically if that information doesn’t change quite as often. When a cache service is suitable? In any situations where you need to … Read more

More Java 8 Method Reference

This tutorial covers more Method Reference examples. If you haven’t already, I first advise you to read the introduction on this subject. Method References types in Java 8 In Java 8 you can have: Reference to static method: Math::sqrt; Reference to instance method of an object: person::getInfo, this::listenTo; Reference to instance method of a particular … Read more