shutdown
Gracefully shuts down the DatabaseManager and closes all database connections.
This method performs a complete cleanup of the database connection infrastructure, ensuring that all resources are properly released and no connections are left open. It is designed to be called during plugin shutdown or when the database system needs to be completely reset.
Shutdown Process:
Checks if the DataSource exists and is not already closed
Calls the HikariCP DataSource close() method to:
Close all active connections in the pool
Cancel any pending connection requests
Release all connection pool resources
Shut down internal HikariCP threads
Resets the initialization flag to prevent operations on closed resources
Logs the shutdown status for monitoring and debugging
Resource Cleanup: The method ensures that all database-related resources are properly cleaned up:
Active database connections are closed gracefully
Connection pool threads are terminated
Memory used by the connection pool is released
Any pending database operations are cancelled safely
Idempotent Operation: This method can be called multiple times safely. If the DataSource is already null or closed, the method will simply log the current state and return without attempting any operations that could cause errors.
Thread Safety: The shutdown process is thread-safe and can be called from any thread. However, calling this method while other threads are actively using database connections may cause those operations to fail with connection exceptions.
State Management: After shutdown completion:
The
initializedSuccessfullyflag is set to falseThe
dataSourcereference remains but points to a closed DataSourceThe
isInitializedproperty will return falseAny subsequent connection requests will trigger re-initialization attempts
Logging: The method provides clear logging about the shutdown process:
Success: Logs that the connection pool was closed successfully
Already closed: Logs that the pool was already closed (not an error)
Helps with debugging connection lifecycle issues
Usage Context: This method should be called in the following scenarios:
Plugin shutdown (onDisable() method)
Database configuration changes requiring reconnection
Error recovery scenarios where a complete reset is needed
Testing scenarios where clean teardown is required
Since
1.0.0
See also
for the corresponding initialization method
for the underlying connection pool shutdown