Tomcat を長時間起動していると、メモリリークなどでOutOfMemoryError が出ることがあります。
これについてはログを監視して、デーモンを再起動させてやらないと対処できないと思っていたのですが、8u92 で追加された ExitOnOutOfMemoryError もしくは CrashOnOutOfMemoryError に関する JVM オプションをつけてあげれば、OOM が出たときに JVM が死ぬようにできることが分かったのでメモ。systemd などと組み合わせれば勝手に蘇らせてもらえるので対処も楽ちんですね。
Java™ SE Development Kit 8, Update 92 Release Notes
New JVM Options added: ExitOnOutOfMemoryError and CrashOnOutOfMemoryError
Two new JVM flags have been added:
- ExitOnOutOfMemoryError - When you enable this option, the JVM exits on the first occurrence of an out-of-memory error. It can be used if you prefer restarting an instance of the JVM rather than handling out of memory errors.
- CrashOnOutOfMemoryError - If this option is enabled, when an out-of-memory error occurs, the JVM crashes and produces text and binary crash files (if core files are enabled).
See JDK-8138745.
具体的には JVM オプションに以下のいずれかの指定を入れてやればOKです。
† 参考
このエントリへのTrackbackにはこのURLが必要です→https://blog.cles.jp/item/10832
コメントは承認後の表示となります。
OpenIDでログインすると、即時に公開されます。
OpenID を使ってログインすることができます。