Friday, January 18, 2019

Custom Thread Pool for Schedule job in SpringBoot

By default, default thread pool is used for schedule job. Number of thread in this pool is small. If we have many scheduled tasks, they could be delayed. We need to declare a dedicated thread pool for scheduled tasks. Below is an example thread pool (pool size 8) in Spring Boot.

Friday, December 7, 2018

Send GET/POST request with Spring Framework

Add httpclient to dependency list Below is an HttpUtil to send GET/POST request using Spring RequestTemplate

Saturday, February 4, 2017

Gradle to Maven Convertion

Just need to add Maven plugin to build.gradle


Then run the command 'gradlew.bat install'

The pom file for maven build will be available under build/poms named 'pom-default.xml'

Copy the 'pom-default.xml' to build.gradle directory and rename to 'pom.xml'.

Now you can build project by maven command 'mvn clean install'

Indicate Java version

If the build is failed due to 'diamond operator is not supported in -source 1.5 (use -source 7 or higher to enable diamond operator)', you need to add 'maven-compiler-plugin' to the pom file and re-run command 'mvn clean install'


Sunday, January 1, 2017

Java Post JSON data

GSON library is good tool to convert data to JSON format 1. Add GSON dependency, current latest version is 2.8.0 2. The data sender util look like:

How To Get Source IP Address from HttpServletRequest

The address of source of request is stored in the header of HttpServletRequest so it is simply to get it. If it is not available in header so we can get the RemoteAddress. Mark dependency to package javaee-web-api, current latest verion is 7.0 The util look like:

Saturday, December 24, 2016

An useful util to handle nested collection in Java

An useful util to separate a list to multiple sublist in Java

Assume that you need to group/separate a List of object to multiple sublist with an specified size, below use should be useful.