The Java Stream API is a wonderful tool, but not without its shortcomings. There is a bug in Java 8 & 9 which affects the number of threads used by a parallel stream in a seemingly unpredictable way. Beware!
Code Soapbox Posts
By default, Spring Boot uses an OpenEntityManagerInViewInterceptor which “binds a JPA EntityManager to the thread for the entire processing of the request […] to allow for lazy loading in web views despite the original transactions already being completed”.
In other words, in every
@RestController action, instead of throwing a
LazyInitializationException when you forget to fetch a lazy-loaded property, Spring will now fetch the property outside of the original transaction. The pattern (or antipattern) is called Open Session In View (OSIV) and, while it sounds fairly useful, is not a good choice for production environments.
The following is a short case study of my latest learning venture and how it lead me to create an app that solves a real-world issue and might earn me some money in the future.
The Builder pattern helps us create complex objects that can have different representations, simplifying the process and (optionally) preserving immutability – encapsulating the code responsible for assembling an object in a separate Builder class.
In simpler terms, it delegates the responsibility of creating a complex object to its Builder, whose job it is to make sure that the object is never created in an invalid state.
Spring Boot, by default, uses Thymeleaf 2 as its template engine. You can, however, make it use the newer version.
In the simplest terms, a factory method is a method which creates objects and lets a class defer instantiation to its subclasses.
It may either be implemented directly in a class (and optionally overriden in its children) or specified in an interface (and implemented by classes which use it).
I once heard a team leader say that there are two types of code: ideal code and code that works in production. It was somehow meant to justify forgoing refactoring because “the code works, don’t touch it!”. My personal opinion is that he should be stripped of his team leading position and given a stern talking to.
The abstract factory pattern provides an interface for creating related objects, while hiding the choice of their concrete classes in implementations of that interface.