How to set JVM parameter values in a java program

筅森魡賤 提交于 2020-02-25 23:52:12

问题


I have a long list of JVM parameter values:

-XX:+UseSerialGC -XX:+ResizePLAB -XX:-ResizeOldPLAB -XX:-AlwaysPreTouch -XX:-ParallelRefProcEnabled -XX:+ParallelRefProcBalancingEnabled -XX:+UseTLAB -XX:-ResizeTLAB -XX:-ZeroTLAB -XX:-FastTLABRefill -XX:+NeverActAsServerClassMachine -XX:-AlwaysActAsServerClassMachine -XX:+UseAutoGCSelectPolicy -XX:+UseAdaptiveSizePolicy -XX:+UsePSAdaptiveSurvivorSizePolicy -XX:-UseAdaptiveGenerationSizePolicyAtMinorCollection -XX:+UseAdaptiveGenerationSizePolicyAtMajorCollection -XX:+UseAdaptiveSizePolicyWithSystemGC -XX:+UseAdaptiveGCBoundary -XX:+UseAdaptiveSizePolicyFootprintGoal -XX:-UseAdaptiveSizeDecayMajorGCCost -XX:+UseGCOverheadLimit -XX:+DisableExplicitGC -XX:-CollectGen0First -XX:+BindGCTaskThreadsToCPUs -XX:+UseGCTaskAffinity -XX:YoungPLABSize=3397 -XX:OldPLABSize=1123 -XX:GCTaskTimeStampEntries=240 -XX:TargetPLABWastePct=6 -XX:PLABWeight=75 -XX:OldPLABWeight=46 -XX:MarkStackSize=4617021 -XX:MarkStackSizeMax=713160576 -XX:RefDiscoveryPolicy=0 -XX:InitiatingHeapOccupancyPercent=48 -XX:MaxRAM=139765086242 -XX:ErgoHeapSizeLimit=0 -XX:MaxRAMFraction=4 -XX:DefaultMaxRAMFraction=4 -XX:MinRAMFraction=2 -XX:InitialRAMFraction=61 -XX:AutoGCSelectPauseMillis=5557 -XX:AdaptiveSizeThroughPutPolicy=0 -XX:AdaptiveSizePausePolicy=0 -XX:AdaptiveSizePolicyInitializingSteps=28 -XX:AdaptiveSizePolicyOutputInterval=0 -XX:AdaptiveSizePolicyWeight=12 -XX:AdaptiveTimeWeight=19 -XX:PausePadding=0 -XX:PromotedPadding=3 -XX:SurvivorPadding=3 -XX:ThresholdTolerance=10 -XX:AdaptiveSizePolicyCollectionCostMargin=49 -XX:YoungGenerationSizeIncrement=16 -XX:YoungGenerationSizeSupplement=104 -XX:YoungGenerationSizeSupplementDecay=9 -XX:TenuredGenerationSizeIncrement=22 -XX:TenuredGenerationSizeSupplement=117 -XX:TenuredGenerationSizeSupplementDecay=2 -XX:MaxGCPauseMillis=13557897735059052544 -XX:GCPauseIntervalMillis=0 -XX:MaxGCMinorPauseMillis=16119267456708329472 -XX:GCTimeRatio=73 -XX:AdaptiveSizeDecrementScaleFactor=4 -XX:AdaptiveSizeMajorGCDecayTimeScale=11 -XX:MinSurvivorRatio=1 -XX:InitialSurvivorRatio=6 -XX:BaseFootPrintEstimate=272901592 -XX:GCHeapFreeLimit=2 -XX:PrefetchCopyIntervalInBytes=654 -XX:PrefetchScanIntervalInBytes=748 -XX:PrefetchFieldsAhead=1 -XX:ProcessDistributionStride=3

that I need to change before running a program. The values for these parameters will be dynamically determined, thus I need to be able to change these values repeatedly. The program is executed inside a docker container and is a REST endpoint developed using springboot.
Is there some kind of configuration file where I can dynamically set these parameters or how can this be done?


回答1:


Is there some kind of configuration file where I can dynamically set these parameters

No.

or how can this be done?

You just write some code to do it. Possibly a shell script or a Windows batch file. Possibly in in some other scripting language. Possibly even in Java.

For example, this uses a helper Java program to do the "dynamic" stuff and generate some JVM options. These are then supplied when launching the JVM for the real application.

#!/bin/sh
OPTS=`java com.acme.GenerateJVMOptions some parameters`
java $OPTS com.acme.TheRealApplication some more parameters


来源:https://stackoverflow.com/questions/59964329/how-to-set-jvm-parameter-values-in-a-java-program

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!