AbhinavRanjan
AbhinavRanjan

Reputation: 1646

Not able to enable Native memory tracking in a spring boot application

I am trying to enable NMT in my spring boot application like this

 java -jar -Dlogging.config=log4j2.xml -XX:NativeMemoryTracking=summary application.jar 

However, I get a warning

Java HotSpot(TM) 64-Bit Server VM warning: Native Memory Tracking did not setup properly, using wrong launcher?

How can I enable NMT for an application running on embedded tomcat?

Upvotes: 9

Views: 5236

Answers (2)

Anatoly Shipov
Anatoly Shipov

Reputation: 504

If you run one JVM per environment (e.g. in container), JAVA_TOOL_OPTIONS is the place for flags:

JAVA_TOOL_OPTIONS=-XX:NativeMemoryTracking=summary -Dlogging.config=log4j2.xml java -jar application.jar

Upvotes: 1

apangin
apangin

Reputation: 98630

Change the order of arguments:

java -XX:NativeMemoryTracking=summary -Dlogging.config=log4j2.xml -jar application.jar

This is a pecularity of java launcher. -XX:NativeMemoryTracking must be handled both by the launcher and by the JVM in order to take effect. However, the launcher stops processing arguments as soon as it sees a terminal option. -jar is one them.

Upvotes: 21

Related Questions