Determine the optimal Java runtime options before running?

we are launching a Java application for rendering ans displaying quite a lot of images. To make this smooth, we like to assign enough heaps of space and would like to check if there is a 64-bit version on the computer. We would like to run the application on different computers, so manually check the available memory and the version of Runtime for a trial version, and the error is a rather difficult problem.

Does anyone know of a method for determining available memory, which can be reserved for heap space, and for determining available JREs; so could we somehow pass these JRE parameters when executing jars?

I know that this will require some kind of batch file, as discussed in this thread:   Setting startup options in a Java class

Does anyone come across a working example for a Windows environment? My knowledge of Windows batch files is limited at best.

Regards, Marius

+4
source share
1 answer

to check if Java is 64-bit:

java -version 2>&1|find /i "64-Bit" && echo YEP!||echo NOPE!

To get free memory:

wmic os get freephysicalmemory

or

systeminfo | find "Physical Memory"

EDIT A universal and quick way to get free memory:

mshta "javascript:close(new ActiveXObject('Scripting.FileSystemObject').GetStandardStream(1).Write(GetObject('winmgmts:').ExecQuery('Select * from Win32_PerfFormattedData_PerfOS_Memory').ItemIndex(0).AvailableBytes));"|more

assign the result to a variable:

for  /f "usebackq" %%a in (`mshta ^"javascript^:close^(new ActiveXObject^(^'Scripting.FileSystemObject^'^).GetStandardStream^(1^).Write^(GetObject^(^'winmgmts:^'^).ExecQuery^(^'Select * from Win32_PerfFormattedData_PerfOS_Memory^'^).ItemIndex^(0^).AvailableBytes^)^);^"^|more`) do set free_mem=%%a
+2
source

Source: https://habr.com/ru/post/1524020/


All Articles