com.hazelcast.core

## Class OutOfMemoryHandler

- java.lang.Object
- - com.hazelcast.core.OutOfMemoryHandler

- Direct Known Subclasses:
    DefaultOutOfMemoryHandler

      public abstract class OutOfMemoryHandler
      extends Object

  Handler for `OutOfMemoryError`.

  When an `OutOfMemoryError` is caught by Hazelcast threads, `OutOfMemoryHandler` is called for ALL `HazelcastInstance`s known by the current JVM (actually ClassLoader).

  Warning: `OutOfMemoryHandler` may not be called even if JVM throws `OutOfMemoryError` because the error may be thrown from an external (user) thread, so Hazelcast may not be informed about `OutOfMemoryError`.

  See Also:
    `OutOfMemoryError`, `Hazelcast.setOutOfMemoryHandler(OutOfMemoryHandler)`

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `OutOfMemoryHandler()`

  - ### Method Summary

    All Methods Instance Methods Abstract Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `abstract void` | `onOutOfMemory(OutOfMemoryError oome, HazelcastInstance[] hazelcastInstances)` When an `OutOfMemoryError` is caught by Hazelcast threads, this method is called for ALL `HazelcastInstance`s knows by current JVM (actually ClassLoader).
    `boolean` | `shouldHandle(OutOfMemoryError oome)` Decides if the OutOfMemoryError thrown will be handled by this OutOfMemoryHandler or not.
    `protected void` | `tryCloseConnections(HazelcastInstance hazelcastInstance)` Tries to close the server socket and connections to other `HazelcastInstance`s.
    `protected void` | `tryShutdown(HazelcastInstance hazelcastInstance)` Tries to shutdown `HazelcastInstance` forcefully; including closing sockets and connections, stopping threads, etc.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### OutOfMemoryHandler

          public OutOfMemoryHandler()

  - ### Method Detail

    - #### onOutOfMemory

          public abstract void onOutOfMemory(OutOfMemoryError oome,
                                             HazelcastInstance[] hazelcastInstances)

      When an `OutOfMemoryError` is caught by Hazelcast threads, this method is called for ALL `HazelcastInstance`s knows by current JVM (actually ClassLoader).

      User can shutdown the `HazelcastInstance`, call `System.exit()`, just log the error, etc. The default handler tries to close socket connections to other nodes and shutdown the `HazelcastInstance`.

      Warning: `OutOfMemoryHandler` may not be called even if JVM throws `OutOfMemoryError` because the error may be thrown from an external (user) thread and Hazelcast may not be informed about `OutOfMemoryError`.

      Parameters:
        `oome` - OutOfMemoryError thrown by JVM
        `hazelcastInstances` - All HazelcastInstances known by JVM, can include inactive or NULL instances.
      See Also:
        `tryCloseConnections(HazelcastInstance)`, `tryShutdown(HazelcastInstance)`

    - #### shouldHandle

          public boolean shouldHandle(OutOfMemoryError oome)

      Decides if the OutOfMemoryError thrown will be handled by this OutOfMemoryHandler or not. If `true` is return, `onOutOfMemory(OutOfMemoryError, HazelcastInstance[])` will be called to handle error, otherwise OutOfMemoryError will be ignored.
      Parameters:
        `oome` - OutOfMemoryError thrown by JVM
      Returns:
        true if OutOfMemoryError will be handled, false otherwise

    - #### tryCloseConnections

          protected final void tryCloseConnections(HazelcastInstance hazelcastInstance)

      Tries to close the server socket and connections to other `HazelcastInstance`s.
      Parameters:
        `hazelcastInstance` - the Hazelcast instance to close server socket

    - #### tryShutdown

          protected final void tryShutdown(HazelcastInstance hazelcastInstance)

      Tries to shutdown `HazelcastInstance` forcefully; including closing sockets and connections, stopping threads, etc.
      Parameters:
        `hazelcastInstance` - the Hazelcast instance to shutdown

Copyright © 2019. All rights reserved.