Tail Recursion Example
Tail recursive saves stack memory.
A recursive function is said to be tail-recursive if there is nothing to do after the function returns except returning its value. In this case, instead of allocating a stack frame for each call, the compiler can rework the code to simply reuse the current stack frame, meaning a tail-recursive function will only use a single stack frame as opposed to hundreds or even thousands of stack frame as in the case of regular recursive calls.
Also, in a tail-recursive case, with each evaluation of the recursive call, the solution (e.g., a running total) is updated through parameter. A smart compiler can make Tail Recursion as efficient as iteration normally is.
We'll see an tail-recursion implementation of Fibonacci at the end of this post. Using Fibonacci as an example, a Fibonacci sequence: [f(0)...f(n)]=[0, 1, 1, 2, 3, 5, 8, 13, ...]
It is not uncommon that you need to watch the runtime performance of a Java application on a server. In this post, I'll show you how to set up a target JVM so you can monitor its cpu, heap memory, threads usage from a specific JMX client - VisualVM. VisualVM is similar to JConsole, a JMX-compliant monitoring tool, but is more advanced.
To use a JMX client, the setup you need to do first are:
Enable JMX Agent for JVM
With JMX agent enabled for a JVM, you can use a JMX Client (JConsole or VisualVM) to tap into your JVM to monitor its performance and memory usage at runtime. Your java runtime is not enabled with JMX by default unless you explicitly specify to turn it on.