How to Solve Error Message java.lang.OutOfMemoryError: Metaspace when Running Wildfly Application Server

Posted on

Introduction

This article is focusing on how to solve an error message appear upon running the Wildfly Application Server’s service. There is a log message appearing in the standalone.bat process. Those messages exist as follows :

...
14:07:33,510 INFO  [org.wildfly.extension.undertow] (MSC service thread 1-1) WFLYUT0007: Undertow HTTPS listener https stopped, was bound to 127.0.0.1:8443
14:07:33,572 INFO  [org.wildfly.extension.undertow] (MSC service thread 1-6) WFLYUT0008: Undertow HTTP listener default suspending
14:07:33,929 WARN  [org.jboss.modules.define] (MSC service thread 1-5) Failed to define class org.jboss.remoting3.spi.AbstractHandleableCloseable$2 in Module "org.jboss.remoting" version 5.0.18.Final from local module loader @24111ef1 (finder: local module finder @1f3f02ee (roots: C:\wildfly-20.0.1.Final\modules,C:\wildfly-20.0.1.Final\modules\system\layers\base)): java.lang.OutOfMemoryError: Metaspace

14:07:33,930 INFO  [org.wildfly.extension.undertow] (MSC service thread 1-6) WFLYUT0007: Undertow HTTP listener default stopped, was bound to 127.0.0.1:8080
14:07:33,933 WARN  [org.jboss.msc.service.fail] (MSC service thread 1-5) MSC000004: Failure during stop of service org.wildfly.remoting.endpoint: java.lang.OutOfMemoryError: Metaspace

14:07:33,934 INFO  [org.wildfly.extension.undertow] (MSC service thread 1-2) WFLYUT0004: Undertow 2.1.3.Final stopping
14:07:34,436 WARN  [org.jboss.modules.define] (ServerService Thread Pool -- 253) Failed to define class org.xnio.XnioWorker$ExternalTaskPool in Module "org.jboss.xnio" version 3.8.1.Final from local module loader @24111ef1 (finder: local module finder @1f3f02ee (roots: C:\wildfly-20.0.1.Final\modules,C:\wildfly-20.0.1.Final\modules\system\layers\base)): java.lang.OutOfMemoryError: Metaspace

14:07:34,438 ERROR [org.jboss.threads.errors] (ServerService Thread Pool -- 253) Thread Thread[ServerService Thread Pool -- 253,5,ServerService ThreadGroup] threw an uncaught exception: java.lang.OutOfMemoryError: Metaspace

14:07:34,439 INFO  [org.jboss.as.clustering.infinispan] (ServerService Thread Pool -- 255) WFLYCLINF0003: Stopped client-mappings cache from ejb container
14:07:34,449 INFO  [org.infinispan.manager.DefaultCacheManager] (MSC service thread 1-8) Stopping cache manager null on null
14:08:07,312 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-3) WFLYSRV0028: Stopped deployment apps.war (runtime-name: egov.war) in 39532ms

Actually, the main error exist in one line exist in the above output command execution :

14:07:34,438 ERROR [org.jboss.threads.errors] (ServerService Thread Pool -- 253) Thread Thread[ServerService Thread Pool -- 253,5,ServerService ThreadGroup] threw an uncaught exception: java.lang.OutOfMemoryError: Metaspace

Furthermore, before the above log output appears, the execution of the Wildfly Application Server is using a default value parameter. Basically, that default value parameter exist on running the ‘standalone.bat’ script file. In this context, the file is ‘standalone.bat’ since the process is in Microsoft Windows-based operating system.  The execution exist as follows :

C:\wildfly-20.0.1.Final\bin>standalone.bat
Calling "C:\wildfly-20.0.1.Final\bin\standalone.conf.bat"
Setting JAVA property to "C:\jdk-14\bin\java"
===============================================================================

  JBoss Bootstrap Environment

  JBOSS_HOME: "C:\wildfly-20.0.1.Final"

  JAVA: "C:\jdk-14\bin\java"

  JAVA_OPTS: "-Dprogram.name=standalone.bat -Xms64M -Xmx512M -XX:MetaspaceSize=96M -XX:MaxMetaspaceSize=256m -Djava.net.preferIPv4Stack=true -Djboss.modules.system.pkgs=org.jboss.byteman  --add-exports=java.base/sun.nio.ch=ALL-UNNAMED --add-exports=jdk.unsupported/sun.misc=ALL-UNNAMED --add-exports=jdk.unsupported/sun.reflect=ALL-UNNAMED"

===============================================================================
...

Solution

There are several solutions for solving the above problem. By default, the size of the heap memory may not suitable for the running Java application. In order to change it, just change the value of the heap memory parameter in the standalone.conf.bat file. The file exist in the bin folder of the root folder of the Wildfly Application Server. As an example, if the root folder exist in ‘C:\wildfly-20.0.1-Final’, the location of the standalone.conf.bat will be in ‘C:\wildfly-20.0.1-Final\bin\standalone.conf.bat’. For a reference, just read the article with the title of ‘How to Increase Heap Memory Allocation for Wildfly Application Server in Microsoft Windows’ in this link.

If changing the heap memory size is not solving the problem, just change the other parameter. That parameter is the metaspace size which is also exist in the standalone.conf.bat file. By default, the metaspace size is 96 M and the maximum size of the metaspace is 256 M. So, adjust the value of the parameter in the standalone.conf.bat. Below is the execution of the standalone.bat file to start the Wildfly Application Server after the adjustment of the metaspace size :

C:\wildfly-20.0.1.Final\bin>standalone.bat
Calling "C:\wildfly-20.0.1.Final\bin\standalone.conf.bat"
Setting JAVA property to "C:\jdk-14\bin\java"
===============================================================================

  JBoss Bootstrap Environment

  JBOSS_HOME: "C:\wildfly-20.0.1.Final"

  JAVA: "C:\jdk-14\bin\java"

  JAVA_OPTS: "-Dprogram.name=standalone.bat -Xms1024M -Xmx1024M -XX:MetaspaceSize=512M -XX:MaxMetaspaceSize=512M -Djava.net.preferIPv4Stack=true -Djboss.modules.system.pkgs=org.jboss.byteman  --add-exports=java.base/sun.nio.ch=ALL-UNNAMED --add-exports=jdk.unsupported/sun.misc=ALL-UNNAMED --add-exports=jdk.unsupported/sun.reflect=ALL-UNNAMED"

===============================================================================

13:35:11,859 INFO  [org.jboss.modules] (main) JBoss Modules version 1.10.1.Final
13:35:12,801 INFO  [org.jboss.msc] (main) JBoss MSC version 1.4.11.Final
13:35:12,813 INFO  [org.jboss.threads] (main) JBoss Threads version 2.3.3.Final
13:35:12,979 INFO  [org.jboss.as] (MSC service thread 1-2) WFLYSRV0049: WildFly Full 20.0.1.Final (WildFly Core 12.0.3.Final) starting
13:35:13,781 INFO  [org.wildfly.security] (ServerService Thread Pool -- 28) ELY00001: WildFly Elytron version 1.12.1.Final
...

So, according to the output above, the metaspace size is 512M and the maximal size of the metaspace is also 512 M.

Leave a Reply