Board logo

标题: [其他] Windows批处理BAT脚本获取32位系统支持的Java参数Xmx的最大值 [打印本页]

作者: HAT    时间: 2014-9-12 12:51     标题: Windows批处理BAT脚本获取32位系统支持的Java参数Xmx的最大值

操作系统版本:
E:\>systeminfo | findstr /c:"OS Name"
OS Name:                   Microsoft(R) Windows(R) Server 2003, Enterprise Edition


Java 版本:
E:\>java -version
java version "1.7.0_67"
Java(TM) SE Runtime Environment (build 1.7.0_67-b01)
Java HotSpot(TM) Client VM (build 24.65-b04, mixed mode, sharing)


测试结果:
E:\>test.bat
Testing: -Xmx1000m OK
Testing: -Xmx1100m OK
Testing: -Xmx1200m OK
Testing: -Xmx1300m OK
Testing: -Xmx1400m OK
Testing: -Xmx1400m OK
Testing: -Xmx1410m OK
Testing: -Xmx1420m OK
Testing: -Xmx1430m OK
Testing: -Xmx1440m OK
Testing: -Xmx1440m OK
Final value is: -Xmx1440m
Press any key to continue . . .


代码:
  1. @echo off
  2. REM ============================================================================
  3. REM Function: Fetch the max value of java option -Xmx in 32 bit Windows system
  4. REM Version: 1.0 @ Sep 10 2014
  5. REM ============================================================================
  6. java -version >nul 2>&1
  7. if errorlevel 1 (
  8.     echo Please make sure you have:
  9.     echo 1. Installed JDK or JRE
  10.     echo 2. Created environment variable %%JAVA_HOME%%
  11.     echo 3. Added environment variable %%JAVA_HOME%%\bin into %%PATH%%
  12.     goto End
  13. )
  14. :StepHundred
  15. for /l %%i in (1000,100,2048) do (
  16.     java -Xmx%%im -version >nul 2>&1
  17.     if errorlevel 1 (
  18.         goto StepTen
  19.     ) else (
  20.         set "Xmx=%%i"
  21.         echo Testing: -Xmx%%im OK
  22.     )
  23. )
  24. :StepTen
  25. for /l %%i in (%Xmx%,10,2048) do (
  26.     java -Xmx%%im -version >nul 2>&1
  27.     if errorlevel 1 (
  28.         goto StepOne
  29.     ) else (
  30.         set "Xmx=%%i"
  31.         echo Testing: -Xmx%%im OK
  32.     )
  33. )
  34. :StepOne
  35. for /l %%i in (%Xmx%,1,2048) do (
  36.     java -Xmx%%im -version >nul 2>&1
  37.     if errorlevel 1 (
  38.         goto ShowResult
  39.     ) else (
  40.         set "Xmx=%%i"
  41.         echo Testing: -Xmx%%im OK
  42.     )
  43. )
  44. :ShowResult
  45. echo Final value is: -Xmx%Xmx%m
  46. :End
  47. pause
复制代码

作者: pkcc110    时间: 2014-9-26 12:18

顶,很不错




欢迎光临 批处理之家 (http://bathome.net./) Powered by Discuz! 7.2