Pages

sizeof in java or how much memory is this object going to consume

Introduction

Ever wonder what is the size of an object? How much space does it take up? And where can I find out this info?
 
 
In this post we will try to answer these question. And see what difference does it make if you use primitives vs Objects (for example float vs Float).
 
The code used in this example is available here for you to try out. I ran my code with JDK 21. Feel free to try out other versions and see if makes a difference.  

Identifying which Java thread is consuming the most CPU

I didn’t come up with this. I was shown how to do this by an esteemed college at work. I only tested this on Linux.


Introduction

Most (if not all) productive systems doing anything important will use more than 1 java thread. And when something goes crazy and your cpu usage is on 100%, it is hard to identify which thread(s) is/are causing this. Or so I thought. Until someone smarter than me showed me how it can be done. And here I will show you how to do it and you too can amaze your family and friends with your mad geek skillz.

 

Automagically adding 'ready to go' users to Congnito

 Step 1

Add the users via CSV upload and ensure the users get created. The user's will have the status 'RESET_REQUIRED'. But in order to use these users, we need the status to be 'CONFIRMED'. This can be done by setting the password for the user as an admin

Postgres Timestamps and Java

Postgres timestamps are up to microseconds resolution. This can be seen here in the Postgres V13 docs. This means that if you are trying to save a ZonedDateTime type into to the DB, you should cut-off the Nano-seconds portion of the time. Otherwise, if you save a time with Nano secs, and you read that time back from the DB, you will have different times. This is because the time from the DB is missing the nano-secs. So how does one go about doing this?

Creating PDFs in Java

What's a good way to make PDFs in java? iText, pdfbox, and perhaps other libraries?

However there is another way to create PDFs which is (at least for me and my use case) easier. And that is: create a HTML. Then convert that HTML into a PDF using flying saucer.

How to get two docker-compose services to talk to each other

Imagine you have two services that are started by two different docker-compose files. And you would like these two services to talk to each other. How can we achieve this?

Why would you want to do this in the first place?

I had a use-case for this, that's why! The use case was as follows:

I have a docker-compose file that contains linux-swag and mysql. These are resources that are not updated very often. So I can start them and forget about them.

I have another docker-compose file that contains a Spring Boot application. This application can have different versions (prod, staging, dev). And these version get automatically deployed on each git-push.

Ubuntu Wireless iwlwifi and Windows 10 Dual Boot

If you have Windows 10 and an Ubuntu Dual boot, this may cause your wireless in Ubuntu to stop working. And the culprit seems to the the 'Fast startup' option in Windows. What you need to do is described here. Make sure that 'Fast startup' is turned off! Otherwise it can be that your iwlwifi doesn't get loaded into the Linux Kernel.