HashMap collisions and how JDK handles it

I was thinking on this question How does HashMap handle collisions internally? What changes were introduced in Java 8 for its implementation? and reading this blog says On a final note, from Java 8, the linked lists are dynamically replaced with balanced binary search trees in collision resolution after the number of collisions in a given bucket location exceed a certain threshold. Than I wonder how it works and went and found the source code of hash map in openjdk. It is a very long class, almost 2600 lines, but so many comments 🤓 it is not very common to see this much comment in a java code, anyway then I start reading it and wanted to note down how it behaves on collusion ...

November 27, 2024 · 3 min · Özkan Pakdil

FFM (Foreign Function and Memory) Stdlib Example

FFM is the new API trying to replace JNI and jep is here It is basically calling functions outside of JVM or accessing memory not managed by JVM. I wanted to test can FFM beat regular Java API, below you can find a simple test doing math sin with FFM and with regular Math.sin import java.lang.foreign.FunctionDescriptor; import java.lang.foreign.Linker; import java.lang.foreign.MemorySegment; import java.lang.foreign.SymbolLookup; import java.lang.foreign.ValueLayout; public class FFMSinTest { public static void main(String[] args) throws Throwable { Linker linker = Linker.nativeLinker(); SymbolLookup stdlib = linker.defaultLookup(); // Locate the "sin" function in the C math library MemorySegment sinAddress = stdlib.find("sin").orElseThrow(); FunctionDescriptor descriptor = FunctionDescriptor.of(ValueLayout.JAVA_DOUBLE, ValueLayout.JAVA_DOUBLE); var sinHandle = linker.downcallHandle(sinAddress, descriptor); double angle = Math.PI / 4; // 45 degrees in radians // Timing Java's Math.sin() long javaStartTime = System.nanoTime(); for (int i = 0; i < 1_000_000; i++) { double result = Math.sin(angle); } long javaEndTime = System.nanoTime(); long javaDuration = javaEndTime - javaStartTime; // Timing C sin via FFM long ffmStartTime = System.nanoTime(); for (int i = 0; i < 1_000_000; i++) { double result = (double) sinHandle.invoke(angle); } long ffmEndTime = System.nanoTime(); long ffmDuration = ffmEndTime - ffmStartTime; System.out.println("Java Math.sin() took: " + javaDuration / 1_000_000.0 + " ms"); System.out.println("C sin (FFM) took: " + ffmDuration / 1_000_000.0 + " ms"); } } And result is ...

November 11, 2024 · 2 min · Özkan Pakdil

How to publish JetBrains Rider plugin for opentelemetry/honeycomb

I had the chance to work with honeycomb.io 2 weeks ago, mainly I was changing the code which sends data too appinsights azre now needed to send data to honeycomb too. It was not too complex but it is hard to catch those log lines and make sure if we called the endpoint correctly and what data we sent. There is wonderful plugin for that for appinsights https://github.com/Socolin/ApplicationInsightsRiderPlugin but there was no plugin whcih can show opentelemetry calls, yes honeycomb.io uses OTEL protocol meaning opentelemetry which is kind of industry standard now for observability. ...

October 6, 2024 · 2 min · Özkan Pakdil

Creating Installers for Java Applications with jpackage

Jpackage, a powerful tool introduced in Java 14. In this blog post, I’ll explore how to use jpackage to create installers for different operating systems, with a focus on creating an MSI installer for Windows. What is jpackage? jpackage is a packaging tool that comes bundled with the Java Development Kit (JDK) since version 14. It allows developers to package Java applications into platform-specific packages that can be easily distributed and installed. It contains the JRE in the generated package and one trigger executable for specified platform. jpackage supports creating various types of installers, including: ...

June 29, 2024 · 2 min · Özkan Pakdil

Spring boot 3 RestClient and RestTemplate logging http requests and response

In Spring boot(SB) 2 the configuration was different, now in SB3 we need to configure the rest client differently. Before SB3 there was RestTemplate now there is new Rest api coming in spring world. Find more details here. Adding the required dependency which will do the real http logging here. implementation 'org.apache.httpcomponents.client5:httpclient5:5.3.1' The big difference is properties configuration, it is changed and not documented on spring site logging.level.org.apache.hc.client5.http.wire=DEBUG logging.level.org.apache.hc.client5.http=DEBUG Using only “wire” will give request/response dump. And that extra http=DEBUG will give connection and more debug log, find it at the end of the page. ...

May 18, 2024 · 8 min · Özkan Pakdil