Class DisposeManager
- java.lang.Object
-
- com.sodius.oslc.server.core.DisposeManager
-
public class DisposeManager extends Object
A central place to register commands to execute when the application is shutdown, which is when it callsdispose()
. This is useful to register clean-up tasks, to ensure resources and background jobs are not left over on shutdown.What shutdown means exactly depends on the application itself and how it integrates in its environment. It can be when the servlet context is destroyed or when the plug-in is stopped, if the application is a plug-in in its host product. Shutdown is when nothing in the application is to continue executing in any way.
Client application may use
add(Runnable)
to register a command to execute on shutdown. Client application must calldispose()
when it is shutdown.- Since:
- 3.11.0
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(Runnable command)
Registers a command to execute when the application is shutdown, which is whendispose()
is called.void
dispose()
Indicates the application is shutdown and allregistered
commands are to execute.static DisposeManager
getInstance()
Returns the dispose manager instance.void
remove(Runnable command)
Unregisters a command that was previouslyadded
.
-
-
-
Method Detail
-
getInstance
public static DisposeManager getInstance()
Returns the dispose manager instance.- Returns:
- the dispose manager instance
-
add
public void add(Runnable command)
Registers a command to execute when the application is shutdown, which is whendispose()
is called. The command is expected to perform its own error handling by catching exceptions as appropriate.The given
Runnable
instance will stay in memory as long as the application is alive. Callers should be cautious and make sure not to hold too much data in memory along this command. Best practice is to register a reference to a method, like below:DisposeManager.getInstance().add(myObjectToDispose::dispose);
Also take in consideration that the command executes when application terminates normally, not in case of a crash.
- Parameters:
command
- a command to execute on application shutdown- Throws:
NullPointerException
- if command is null
-
remove
public void remove(Runnable command)
Unregisters a command that was previouslyadded
.- Parameters:
command
- a command to no longer execute on application shutdown- Throws:
NullPointerException
- if command is null
-
dispose
public void dispose()
Indicates the application is shutdown and allregistered
commands are to execute.What shutdown means exactly depends on the application itself and how it integrates in its environment. It can be when the servlet context is destroyed or when the plug-in is stopped, if the application is a plug-in in its host product. Shutdown is when nothing in the application is to continue executing in any way.
-
-