In another article, I have introduced to Spring Cache Abstraction. Following that article, In this article, I am going to show you how to configure Ehcache in the Spring Boot application(similarly, you can do for non-spring application by adding more dependencies).
Before jumping to the code demo section, I want to have a quick introduction to Ehcache, spring-boot-autoconfigure module, and spring-context-support module. Going through these pieces should be great to understand more what I do in the code demo section.
Ehcache is an open-source, standards-based cache that boosts performance, offloads your database, and simplifies scalability. It’s the most widely-used Java-based cache because it’s robust, proven, full-featured, and integrates with other popular libraries and frameworks. …
Caching is well-known as the most approach to increase application performance. Caching helps reduce the cost of CPU expensive operations such as Fibonacci calculation. Besides CPU expensive operations, caching also helps reduce IO expensive operations such as reading files from disk. Unfortunately, efficiently applying cache into the application is no simple task.
Spring Framework provides cache implementation in the spring-context module with a simple cache store that is ConcurrentHashMap
if no cache library found on the classpath. Otherwise, in case we have included supported cache libraries in the classpath,
With the spring cache, It has many built-in annotations to manage cache by common actions such as write to cache, evict cache, or update cache. We will jump into detail of Spring Cache annotations in the next section. …
Any good developers know that fetching large data then render the view or response within a single request is a bad idea for a high-performance application. So in this article, I would like to share with you how to do paging and sort data with Spring Data JPA. This article gives you a solution to handle the most popular feature in most applications such as displaying products in the e-commerce system.
Before going to the demo, I would like to share with you how Spring Data JPA supports developers for doing paging and sorting.
Spring Data JPA already provides many solutions that allow us querying data easier such as Query Method, Query Method, or four repository interface(JpaRepository
, PagingAndSortingRepository
, CrudRepository
, Repository
). These features are powerful, which help me a lot when building an application with Spring Data JPA. But a lot of time we still need to custom query or method to meet expectations or requirements.
The class design diagram above indicates how we can create a custom repository in Spring Data JPA. We just need to let EmployeeRepository implement the custom interface and define the implementation for the customized repository. …
Version Control is very important to make sure any change in the source code should be recorded and allow us to recall a specific version later. Imagine we edit some lines of code then deploy it without full-test then the error occurs due to the changes, unfortunately, we forgot to make a backup of the old code. Now how do we can revert to the previous version? In order to avoid these problems, we need a version control system to record and keep track of all changes in our code.
A version control system allows us to revert a selected file back to a previous version or revert the entire project. It also allows us to see who last modified and so on. …
H2 database is an open-source in-memory database that can be easily embedded into Java application. H2 database provides a list of features such as Pure Java, memory mode, encrypted database, ODBC driver even full-text search. Its size approx around 2MB.
H2 database also provides a browser-based Console application to manage data.
In this article, we will learn about message term in Spring Integration
In order to loose coupling between components in a system, we typically apply the messaging system to achieve that aim. That requires a solid understanding of what is a message and some type of message for effective use for specific scenarios. So in this article, I would like to share the definition of the message, the structure of a message, and common types of messages in a messaging system.
As the spring integration reference document defined that “In Spring Integration, a message is a generic wrapper for any Java object combined with metadata used by the framework while handling that object. …
In modern software architecture, the application needs to be decoupled, high scalability, serving high performance. Messaging service come in allows us to build that kind of application. Therefore with a solid understanding of messaging models is the key to build an effective system. There are two commonly messaging models, the point-to-point and the publish/subscribe model. Both of these messaging models are based on the message queue know as a central place to send messages to or place to get the message from. The sent messages are ordered in the message queue except it has higher priority. …
In Java language, it has two types of variables, primitive variable, and reference variable. In some cases, we want to use the primitive variable as an object to get the benefits of an object like allowing null
or encapsulation. For those cases, we can use wrapper classes to do that thing. There are eight classes to wrap the primitive value in an object in Java language:
java.lang.Byte
wraps byte
valuejava.lang.Short
wraps short
valuejava.lang.Integer
wraps int
valuejava.lang.Long
wraps long
valuejava.lang.Float
wraps float
valuejava.lang.Double
wraps double
valuejava.lang.Char
wraps char
valuejava.lang.Boolean
wraps boolean
valueA wrapper class is like a box where we can put the primitive value. The box has holes that allow us to put values from different types or convert the holding value to another type. …
As we know, any server or computer stores data on the hard disk and in the RAM(Random Access Memory). The RAM is the temporary storage while the hard disk is the permanent computer storage. When comparing the speed of these storages, RAM has extremely faster than hard disk even of SSD. RAM can transfer thousands of megabytes per second while the hard disk only gives us around 50 to 250MB/s. Now we might think that we can temporarily store data in RAM to increase reading and writing speed for the application. The act of temporarily storing data in a RAM is called in-memory caching. …
About