I am trying to get my Java code to run, but whenever I try the metaspace starts to get full. At first I didn't even notice it since it takes a long time (~1 month) to run full and crash.
The first thing I did was to look into the code, if there were Objects being created and filled with a lot of data and not deleted by the GC. After determining that this was (most likely) not the case I wrote a little test programm which results in the same error.
In my main I call a new TimerTask and assign a Timer to it. Afterwards I just schedule it.
TestTimer testTimerTask = new TestTimer();
Timer timer = new Timer("test");
timer.scheduleAtFixedRate(testTimerTask, 0, 100);
And here the TimerTask itself which just creates a bunch of Objects that should be deleted afterwards.
public class TestTimer extends TimerTask{
private long x = 0;
@Override
public void run() {
String str = "";
for (int i = 0; i < 10000; i++) {
if(x >= 2147483647) {
x = 0;
}
str = new String("" + x);
x++;
}
}
}
So I tried debugging it. For this I used the 2.0.4 Version of VisualVM. After letting it run for some time I got these two pictures of the Metaspace and the Heap.
In addition here's my JVM arguments,
-Xms64m
-Xmx128m
-Dlog4j.configurationFile=./log4j2.xml
my JVM Version OpenJDK 64-Bit Server VM (11.0.8+10, mixed mode) and my Java Version version 11.0.8, vendor Oracle Corporation.
Is there anything I can do to troubleshoot this problem some more and to stop my metaspace from filling up?