Browsed by
Month: November 2016

Don’t rely on Java finalizers

Don’t rely on Java finalizers

java-logo
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
[java]
protected void finalize() {
logger.info(“start important work before GC”);
fooBar.persist(this.getDataMap());
}
[/java]

Read More Read More

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

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

terminal-app
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 Read More

Apple MacBook Pro late 2016

Apple MacBook Pro late 2016

apple.com

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 Read More