java选项_Java Language

Example

The java command supports a wide range of options:

All options start with a single hyphen or minus-sign (-): the GNU/Linux convention of using -- for "long" options is not supported.

Options must appear before the or the -jar argument to be recognized. Any arguments after them will be treated as arguments to be passed to Java app that is being run.

Options that do not start with -X or -XX are standard options. You can rely on all Java implementations1 to support any standard option.

Options that start with -X are non-standard options, and may be withdrawn from one Java version to the next.

Options that start with -XX are advanced options, and may also be withdrawn.

Setting system properties with -D

The -D= option is used to set a property in the system Properties object. This parameter can be repeated to set different properties.

Memory, Stack and Garbage Collector options

The main options for controlling the heap and stack sizes are documented in Setting the Heap, PermGen and Stack sizes. (Editorial note: Garbage Collector options should be described in the same topic.)

Enabling and disabling assertions

The -ea and -da options respectively enable and disable Java assert checking:

All assertion checking is disabled by default.

The -ea option enables checking of all assertions

The -ea:... enables checking of assertions in a package and all subpackages.

The -ea:... enables checking of assertions in a class.

The -da option disables checking of all assertions

The -da:... disables checking of assertions in a package and all subpackages.

The -da:... disables checking of assertions in a class.

The -esa option enables checking for all system classes.

The -dsa option disables checking for all system classes.

The options can be combined. For example.

$ # Enable all assertion checking in non-system classes

$ java -ea -dsa MyApp

$ # Enable assertions for all classes in a package except for one.

$ java -ea:com.wombat.fruitbat... -da:com.wombat.fruitbat.Brickbat MyApp

Note that enabling to assertion checking is liable to alter the behavior of a Java programming.

It is liable make the application slower in general.

It can cause specific methods to take longer to run, which could change timing of threads in a multi-threaded application.

It can introduce serendipitous happens-before relations which can cause memory anomalies to disappear.

An incorrectly implemented assert statement could have unwanted side-effects.

Selecting the VM type

The -client and -server options allow you to select between two different forms of the HotSpot VM:

The "client" form is tuned for user applications and offers faster startup.

The "server" form is tuned for long running applications. It takes longer capturing statistic during JVM "warm up" which allows the JIT compiler to do a better of job of optimizing the native code.

By default, the JVM will run in 64bit mode if possible, depending on the capabilities of the platform. The -d32 and -d64 options allow you to select the mode explicitly.

1 - Check the official manual for the java command. Sometimes a standard option is described as "subject to change".

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值