Posts

Showing posts with the label Java 21

Testing JVM resources availability in docker environment

Introduction JVM is changing over the time what makes us, Software Engineers, to periodically measure stability of our applications. JVM flag adaptations can be needed not only when upgrading JDK but also when we are changing available app cloud resources. If we pay for resources, we should use them in the most effective way. This article provides useful scripts and code to make resource control easier. All scripts and code used in this article you can find in this GitHub demo Testing JVM flags To test default JVM flags values depending on given resources I’m using script docker-jvm-flags.sh (available on github repo). You can easily modify it according to your preferences. Basically it runs JRE docker image with given memory and CPUs resources and for each of them executes command to get default JVM flags and filtering (with grep) those, which we specified on JVM_FLAGS_TO_PRINT list. docker-jvm-flags.sh JVM_IMAGE_NAME="e...

Java 21 vs. Java 11 - practical comparison

Image
Introduction This study aims to compare some metrics related to Java 11 and Java 21 applications and based on it, approximate the value of savings due to migration. In the tests I used following JDKs: - for Java 11: Coretto openjdk 11.0.19 2023-04-18 LTS - for Java 21: Oracle openjdk 21.0.1 2023-10-17 Hardware: - model: Lenovo Y50-70 - RAM: 16GB DDR3 1600MHz - CPU: Intel Core i7-4720HQ (Quad Core, 2.6GHz - 3.6GHz, 6MB Cache) - OS: Ubuntu Desktop 22.04.3 LTS Application which I've tested is available here Tested aspects Each test was done 10 times, one by one. Collected values description: - application start time – logged in application output: - application initial memory usage – RAM memory usage after application started (by PID from app logs): - application memory usage after init – RAM memory usage after sending request to application endpoint (by PID from app logs): ...

Keycloak config for Java application with Spring (Java 21)

If you want to secure your Spring microservice endpoints with Keycloak, you are in perfect place. Let’s do this step by step. First we need is of course to add proper dependencies, I’m using maven: <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-security</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-oauth2-resource-server</artifactId> </dependency> </dependencies> Second, provide some properties for our authorization server connection: spring: security: oauth2: resourceserver: jwt: issuer-uri: http://localhost:8080/realms/custom-realm jwk-set-uri: http://localhost:8080/realms/custom-realm/protocol/openid-connect/certs Thi...

Postgres database connection for Spring app (Java 21)

Dependencies: &ltdependencies&gt &ltdependency&gt &ltgroupId&gtorg.postgresql&lt/groupId&gt &ltartifactId&gtpostgresql&lt/artifactId&gt &lt/dependency&gt &ltdependency&gt &ltgroupId&gtorg.springframework.boot&lt/groupId&gt &ltartifactId&gtspring-boot-starter-data-jpa&lt/artifactId&gt &lt/dependency&gt &lt/dependencies&gt Properties short way: spring: datasource: url: jdbc:postgresql://localhost:5432/custom_database username: postgres password: password # if you want your app to auto create tables on start: # jpa: # hibernate: # ddl-auto: create And a little more advanced: spring: jpa: properties: hibernate: jdbc: time_zone: UTC datasource: url: jdbc:postgresql://localhost:5432/custom_database user...