Java Service Wrapper - JVM Hang的處置

Java Service Wrapper提供了JVM發生問題時的處置。有天在執行我們系統的某個功能時,由於超過wrapper預設允許JVM Hang的時間,導致它重新啟動了JVM,也造成功能無法正常執行完畢。本篇文章主要告訴大家,關於JVM沒有回應處置的相關設定。這些設定都可以在官網文件中找到。

設定沒有回應的允許時間,預設30秒。假如有某些操作會造成JVM hang住,那你就需要tune這個值:

wrapper.ping.timeout=30

設定timeout後的處置,預設為重新啟動JVM。它是可以透過逗點設定多個,詳細設定可以看Reference 1:

wrapper.ping.timeout.action=RESTART

而在wrapper log中想要知道這些處置,就必須設定正確的log level,至少要STATUS以上才能獲得這些資訊:

wrapper.console.loglevel=STATUS

參考此連結,可以透過以下指定去模擬JVM hang住5分鐘:

pkill -STOP java; sleep $(( 5 * 60 )); pkill -CONT java

但因為這不夠精確,會造成系統上所有java程式hang住,如果能取得pid,建議使用以下command:

$pid=12345
kill -STOP $pid
sleep 5
kill -CONT $pid

以下為log範例輸出:

STATUS | wrapper  | 2016/08/19 13:24:10 | --> Wrapper Started as Daemon
STATUS | wrapper  | 2016/08/19 13:24:11 | Java Service Wrapper Standard Edition 64-bit 3.5.26
STATUS | wrapper  | 2016/08/19 13:24:11 |   Copyright (C) 1999-2014 Tanuki Software, Ltd. All Rights Reserved.
STATUS | wrapper  | 2016/08/19 13:24:11 |     http://wrapper.tanukisoftware.com
STATUS | wrapper  | 2016/08/19 13:24:11 |   Licensed to Tony Lin
STATUS | wrapper  | 2016/08/19 13:24:11 |
STATUS | wrapper  | 2016/08/19 13:24:12 | Launching a JVM...
WARN   | wrapper  | 2016/08/19 13:26:22 | JVM process was stopped.  It will be killed if the ping timeout expires.
STATUS | wrapper  | 2016/08/19 13:26:36 | JVM appears hung: Timed out waiting for signal from JVM.  Restarting JVM.
ERROR  | wrapper  | 2016/08/19 13:27:10 | Shutdown failed: Timed out waiting for signal from JVM.
ERROR  | wrapper  | 2016/08/19 13:27:11 | JVM did not exit on request, termination requested.
STATUS | wrapper  | 2016/08/19 13:27:11 | JVM received a signal SIGKILL (9).
STATUS | wrapper  | 2016/08/19 13:27:11 | JVM process is gone.
STATUS | wrapper  | 2016/08/19 13:27:11 | JVM exited after being requested to terminate.
STATUS | wrapper  | 2016/08/19 13:27:15 | Launching a JVM...