Less common used java parameters

   |   2 minute read   |   Using 337 words

Collection of less used parameters passed to java process.

Aggregated list of less used java parameters, may be useful in some cases.

  1. -XX:OnOutOfMemoryError:

    • Usage: Specify a script or command to execute when an OutOfMemoryError occurs.
    • Example:
      java -XX:OnOutOfMemoryError="kill -9 %p"
      
      This command will kill the Java process (%p) when an OutOfMemoryError is encountered.
  2. -XX:SoftRefLRUPolicyMSPerMB:

    • Usage: Adjust the soft reference LRU policy based on memory consumption.
    • Example:
      java -XX:SoftRefLRUPolicyMSPerMB=1000
      
      This sets the policy to clear soft references more aggressively when memory consumption exceeds 1000 milliseconds per MB.
  3. -XX:MaxDirectMemorySize:

    • Usage: Set the maximum size of direct memory available to your application.
    • Example:
      java -XX:MaxDirectMemorySize=256m -jar myapp.jar
      
      This limits the direct memory to 256 megabytes.
  4. -XX:MaxMetaspaceSize:

    • Usage: Set an upper limit on the size of the metaspace, which stores class metadata.
    • Example:
      java -XX:MaxMetaspaceSize=128m -jar myapp.jar
      
      This caps the metaspace at 128 megabytes.
  5. -XX:ThreadStackSize:

    • Usage: Adjust the stack size for Java threads.
    • Example:
      java -XX:ThreadStackSize=256k -jar myapp.jar
      
      This sets the thread stack size to 256 kilobytes.
  6. -XX:+UseBiasedLocking:

    • Usage: Enable biased locking, which can improve performance in some cases by reducing synchronization overhead.
    • Example:
      java -XX:+UseBiasedLocking -jar myapp.jar
      
      This enables biased locking for the application.
  7. -XX:+UseLargePages:

    • Usage: Enable the use of large memory pages to improve memory management performance.
    • Example:
      java -XX:+UseLargePages -jar myapp.jar
      
      This enables large memory pages for the JVM.
  8. -XX:AllocateHeapAt:

    • Usage: Specify the base address for the heap (used with certain operating systems).
    • Example:
      java -XX:AllocateHeapAt=0x0000000100000000 -jar myapp.jar
      
      This sets the base address of the heap memory.
  9. -XX:FlightRecorderOptions:

    • Usage: Configure Java Flight Recorder (JFR) options for advanced profiling and diagnostics.
    • Example:
      java -XX:FlightRecorderOptions=defaultrecording=true -jar myapp.jar
      
      This enables default JFR recording.
  10. -XX:MaxFDLimit:

    • Usage: Set the maximum number of file descriptors that can be opened by the JVM.
    • Example:
      java -XX:MaxFDLimit=8192 -jar myapp.jar
      
      This increases the maximum file descriptor limit to 8192 for the application.

These less commonly used Java parameters can be helpful in specific situations where fine-tuning or advanced configuration is necessary. However, they should be used with caution, as improper settings can impact application performance and stability.



denis256 at denis256.dev