使用Java Service Wrapper的触发器- 山下的人- JavaEye技术网站

使用Java Service Wrapper的触发器根据服务器状态进行自动restart、shutdown等动作,以下是官方使用说明:

?

?

wrapper.filter.<x>.<n> Properties

A pair of wrapper.filter.trigger.<n> and wrapper.filter.action.<n> properties make it possible to filter the output of a JVM, and then perform some action whenever a specific trigger string is found. The filtering process works by comparing JVM console output against registered triggers until a match is found. At that point, the associated action is executed. Only the first matching trigger will be handled for any line of output. In each trigger/action pair, the "<n>" component of the property name is an integer number counting up from "1". By default, there can be no missing numbers. The property can optionally be set to allow gaps in the sequence.

wrapper.filter.trigger.<n> :

The trigger can be any string.

wrapper.filter.action.<n> :

If an action is omitted, it will default to RESTART .

Possible actions are followings:

  • RESTART : will stop the current JVM and then restart a new invocation.
  • SHUTDOWN : will stop the JVM as well as the Wrapper.
  • DUMP : will invoke a thread dump.
  • NONE : is useful because it will prevent any triggers with a higher number from being triggered.

Examples:

The following example will monitor the JVM output and then restart the JVM automatically whenever a java.lang.OutOfMemoryError is thrown to the console. Depending on where in an application the error is thrown, it is not always possible to trap and handle the error in a useful way from within the JVM.

Filters work by monitoring the console output of the JVM. In order for a trigger to be fired by an exception, the Java application must print the message being filtered to the console.

The next example demonstrates how to trigger a JVM restart whenever the string Error appears anywhere in the output, with the exception of the case where the string is part of the larger string IgnoreError .

The string being filtered can contain spaces. But due to the way the configuration properties are loaded in general, any leading of trailing spaces will be trimmed when the property is loaded.

郑重声明:资讯 【使用Java Service Wrapper的触发器- 山下的人- JavaEye技术网站】由 发布,版权归原作者及其所在单位,其原创性以及文中陈述文字和内容未经(企业库qiyeku.com)证实,请读者仅作参考,并请自行核实相关内容。若本文有侵犯到您的版权, 请你提供相关证明及申请并与我们联系(qiyeku # qq.com)或【在线投诉】,我们审核后将会尽快处理。
—— 相关资讯 ——