Solving java.lang.OutOfMemoryError: Metaspace error

The java.lang.OutOfMemoryError: Metaspace indicates that the amount of native memory allocated for Java class metadata is exausted. Let’s how this issue can be solved in standalone applications and cloud applications. In Java 8 and later, the maximum amount of memory allocated for Java classes (MaxMetaspaceSize) is by default unlimited, so in most cases there is … Read more

How to solve java.lang.OutOfMemoryError: GC overhead limit exceeded

The error “java.lang.OutOfMemoryError: GC overhead limit exceeded” is fairly common for old JDK (mostly JDK 1.6 and JDK 1.7) . Let’see how to solve it. According to the JDK Troubleshooting guide, the “java.lang.OutOfMemoryError: GC overhead” limit exceeded indicates that the garbage collector is running all the time and Java program is making very slow progress. … Read more

Simplest way to read a File in a String with Java 8

Do you need a quick hack to read a text file into a Java String? With Java 8 this is a piece of cake! See this example: import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; public static void main(String[] args) throws IOException { String text = new String(Files.readAllBytes(Paths.get(“myfile.txt”))); } }

Speed up your Java coding with Lombok

We all know that one of the most annoying things in Java is the thing we need to place lots of boiler plate code when building our applications. Think for example of adding Constructors with all fields, getter and setter methods, Logger static methods, not to mention the boilerplate code to use common patterns in … Read more

Getting started with Java-based Machine Learning Libraries

There are over 70 Java-based open source machine learning projects listed on the MLOSS.org website, and probably many more unlisted projects live at university servers, GitHub, or Bitbucket. In this article, we will review the major libraries and platforms, the kind of problems they can solve, the algorithms they support, and the kind of data they can work with. … Read more

Top 5 solutions for Java Http Clients

In this tutorial we will check some of the best solutions if you want to implement an Http Client. You can run the Http Client on the top of WildFly application server or as part of any Java process. First of all, it is worth mentioning that WildFly ships with an embedded Web Server but … Read more

How to kill a Java process from Java

Today I had to write a quick code to find out which Java process is using a Port and eventually killed it. You can use it as template in case you have to manage OS process in Linux from Java code: import java.io.BufferedReader; import java.io.InputStreamReader; public class Execute { public static void main(String[] args) { … Read more

How to check if a port is open in Java

Here is a minimalist Java code which can be used to test if a port is available. In this example, we are checking for port 8080 by opening a new Socket to that port. We allow up to 10 retries if the port has been found already used. Enjoy it! import java.io.IOException; import java.net.Socket; public … Read more

Getting the process id (PID) programmatically in Java 9

Java 9 features a simple an portable way to retrieve the process id of the Java Virtual Machine. This can be done through the ProcessHandle which identifies and provides control of native processes. Each individual process can be monitored for liveness, list its children, get information about the process or destroy it. By comparison, Process … Read more