Don’t rely on Java finalizers

Recently I was facing a problem where a Java application should persist a part of its state when it was closed. This was already implemented but seemed to work just unreliably and it was not clearly reproducible when it worked properly and when it failed. After analyzing the existing source code I figured out that finalizers were used to implement the functionality by delegating the call of the persist logic to the garbage collector. This seems like a very good idea at first but lacks in reliability. As a short note up front don’t use finalizers for important things.

A finalizer is a method which represents the opposite of a constructor. It is a method with the purpose to do some cleanup work, free up some memory and so on which gets called by the garbage collector before the object gets collected. A simple example would look like this

protected void finalize() {"start important work before GC");

Read More »

Posted in coding, english, Java | Tagged , , | Leave a comment

Find and kill a process on a specific port (lsof)

You might all have experienced the situation when you want to start a server either from within your IDE or via the terminal to only get the error that the “port is already in use” and the startup is aborted. This is mostly caused by aborting the server or a crash of the IDE which started it and not terminating it properly. When using macOS (or any other BSD or a Linux) there is a simple solution for this.

For such purposes macOS comes with the “lsof” command which stands for “list open files”. Its purpose is to show who is using a specific file or in our case who is using a specific port. After identifying the process it is easy to terminate it using the “kill” command. Read More »

Posted in Apple, Linux, macOS, Tech, Tools | Tagged , , , , , , , | Leave a comment

Apple MacBook Pro late 2016

This blog should not transform to yet another Apple blog but as a Java Developer the Mac is my preferred platform which I use daily. This is the reason why I tend to take a closer look when Apple shows the next generation of macOS or Mac hardware even if I’m not buying a new one immediately. I want to get a feeling were the platform is going to. Last week Apple showed its last iteration of the MacBook Pro to the public and I want to share my thoughts as a developer about it.

At first I like the new look, the lower weight is really great for me as I often travel around with the MacBook being in my backpack and every grams you could save there is a win. The first thing that got me thinking was if it really is a good idea to start the 13″ model with just 8GB of RAM. From a developer standpoint I think that this is the absolute minimum and you should get an upgrade here if possible. When you are a Java developer and start your app server (sometimes multiple servers at once), a database in a VM, your IDE, Browser, Mail etc this will lead very fast to eating up all the RAM and swapping out to the SSD. SSDs are very fast these days but they are no match to the RAM and it will slow down your system. 16GB will be a better solution here and that Apple doesn’t offer 32GB for the 13″ model is a shame. That they commented afterwards that this decision was made because 32GB would have used to much of the battery is a reason but not one that I like. I would much more like to work a shorter time with a faster system then work longer with a slow system that has used up all its memory because this often makes effective working impossible and I guess in the future we will need more RAM than today instead of less. Read More »

Posted in Apple, english, Tech | Tagged , , , , | Leave a comment

Java Forum Nord 2016

Java Forum Nord
Last week (October 20th) I attended the second “Java Forum Nord” in Hannover. The Java Forum is now in its second year but is the evolution of an older and smaller conference in Göttingen (Source Talk Tage). The relocation and renaming of the conference was necessary because it wasn’t possible to attract an audience huge enough to get top speakers to Göttingen. To make the transfer possible the JUG Deutschland which is located in Göttingen and hosted the Source Talk cooperates now with the JUG Bremen, JUG Hamburg, JUG Hessen (Kassel), JUG Ostfalen, SUN User Group Deutschland and the local JUG Hannover.
As a result the conference professionalized very quickly and the audience grew by a huge number. After the first edition in 2015 took place in a small Hotel at the Hannover main train station and was quickly sold out they relocated to the bigger Hotel Dormero in Hannover which had space for 400 participants and was sold out, too. After I would consider last year as a transition year I had this year the feeling to be on a very serious one day conference which had definitively left the amateur status. What makes this conference so special is that it is organized by the JUGs (Java User Groups) and aims for no profit which makes it possible to give very cheap tickets away. Read More »

Posted in Allgemein, english, general, Java, Reisebericht, Talks | Tagged , , , , , | Leave a comment

Removing Excel rows with POI

When generating Excel Sheets it is sometimes necessary to remove rows which match a given criteria afterwards. The first idea for this would be to use removeRow(Row row) but this has the problem that it deletes all the row contents and leaves the empty row in your sheet which is probably not what you want. To remove the rows as a whole the shiftRows(int startRow, int endRow, int n) is needed.
Lets say we have a xls file with column A being the title which is always filled but we want to remove every row in which the data column B is not filled. For this case the following snippet would be appropriate Read More »

Posted in coding, english, howto, Java | Tagged , , , , | Leave a comment