Loading...

Latest Posts

Spring September 6, 2023

Spring's Assert Class: The Smart Way to Validate

There are many ways to ensure your code does what it’s supposed to do. Java even has a built-in assert language feature for this very purpose. And then there’s Spring’s Assert class. But why should I use this? In this article, we delve deeply into the subject and explore the advantages of using this class for validating your data and arguments. Why Use Assertions at All? Before diving into the details of the Spring Assert class, let’s briefly clarify the significance of assertions.


Spring August 30, 2023

Open Session in View (OSIV) in Spring - Enable or Disable?

If you are working with Spring Boot and Hibernate, you have undoubtedly come across the term “Open Session in View” (OSIV) or its corresponding property open-in-view. But what exactly does this option do, and how does it affect your interaction with the database? Should you enable or disable it? In this article, we delve deep into the topic and shed light on its functionality and differences compared to other approaches.


Spring August 23, 2023

Spring MVC: How to Use a Custom Converter for Type Safety in Controllers

Are your controllers constantly filled with primitives? In ArticleController, the first line of every method is: articleRepository.findById(articleId). We keep making the same conversions. I hardly observe as many primitives in any other layer as in the API layer. This leads to much boilerplate. The code becomes harder to test. And it’s harder to read. Yet we know how much easier it is when we work with type safety. In this article, I will show you how to use the Converter Interface to automatically convert your primitives into the correct type.


Spring August 16, 2023

Avoiding Static Access to SecurityContext with @AuthenticationPrincipal in Spring

In almost every web application, logic related to the user must be executed. To access this, his data is assigned based on his authentication. With Spring Security, the authentication framework in the Spring stack, we have various ways to accomplish this essential task. Static Access and its Drawbacks In many applications and examples, it is common to statically retrieve the SecurityContext in Spring to access the current UserDetails. However, this has some disadvantages:


Performance August 9, 2023

The Optimal Thread-Pool Size in Java: Explaining the Formula

Determining the optimal size of a thread pool in Java is crucial to maximizing CPU and resource utilization. This decision depends on many factors. Here, we’ll show you how to use the famous formula from Brian Goetz’s “Java Concurrency in Practice.” We’ll give you a practical example of how to calculate the ratio of wait time to compute time (W/C). The Formula The formula for the optimal size of a thread pool is:


Top