Java startup parameters

The following Java startup parameters should be used (and the values adjusted) when running a Java process on a server.

When a Java process starts, it overwrites an existing GC log file. I would recommend to either use a timestamp in the filename or use the %pid placeholder.

If you want to use JMX, also add the following parameters:

Functional Interfaces in Java 8

With Java 8, the concept of Lambdas was finally added to the language specification. Often you’re using Lambdas on the fly without assigning them to a variable.

However if you want to save a Lambda into a variable and pass it as a method parameter or use it later, you need to pick the applicable type.

Here is the list of the Interfaces you might use from the Java API:

  • Runnable // nothing
  • Supplier<T> // a return value
  • Consumer<T> // a parameter
  • BiConsumer<T, U> // two parameters
  • Function<T, R> // a parameter and a return value
  • BiFunction<T, U, R> // two parameters and a return value
  • UnaryOperator<T> // the parameter and the return value have the same type
  • BinaryOperator<T> // two parameters and a return value of the same type
  • Predicate<T> // a parameter and a boolean return value
  • BiPredicate<T, U> // two parameters and a boolean return value

InformIT presents all those Interfaces using a nice table in the article “Java SE 8 for the Really Impatient: Programming with Lambdas“.


Linux kills a process when when starving memory

I recently observed a rather strange problem with randomly dying Java processes under heavy load. The vital clue to this problem was hidden in /var/log/messages as shown below:

It turns out that Linux may decide to kill a process when the system runs out of memory. It may make sense to cap the memory limit (-Xmx) of any Java processes running on the system to a value that sums up below the server’s available memory.

Jaan Angerpikk explained this problem in great detail, follow the link below to read more on this matter.

Out of memory: Kill process or sacrifice child

Memory stats on Linux

Did you ever wonder what the VIRT, RES and SHR memory figures in top on Linux are supposed to tell you?

Here we go:

  • VIRT – How much memory the process is able to access at the moment.
  • RES – How much memory the process is actually using at the moment. This is the value you should probably be looking at and corresponds with the %MEM column.
  • SHR – How much of the VIRT memory is shareable.

Continue here if you want more details:

A peek at the man page top might also help:

AdWords conversion tracking from AngularJS

Inspired by a blog post of Zain Zafar, I implemented my own version of a Google AdWords conversion tracking from AngularJS.

Load the AdWords code from your HTML file:

Then add the AdWords service to your Angular app:

The last thing is to call the service from your controller when the conversion happens:


Debug network traffic on a Linux server

Use the following shell command to print all traffic from and to the given IP:

This will print something like this:

This can be quite handy if you need to debug network issues.