Class DisposeManager
dispose().
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 call dispose() when it is shutdown.
- Since:
- 3.11.0
-
Method Summary
Modifier and TypeMethodDescriptionvoidRegisters a command to execute when the application is shutdown, which is whendispose()is called.voiddispose()Indicates the application is shutdown and allregisteredcommands are to execute.static DisposeManagerReturns the dispose manager instance.voidUnregisters a command that was previouslyadded.
-
Method Details
-
getInstance
Returns the dispose manager instance.- Returns:
- the dispose manager instance
-
add
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
Runnableinstance 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
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 allregisteredcommands 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.
-