Fix repo connections not getting closed
This commit is contained in:
@@ -30,6 +30,7 @@ import com.seibel.distanthorizons.core.pos.DhBlockPos2D;
|
||||
import com.seibel.distanthorizons.core.pos.DhChunkPos;
|
||||
import com.seibel.distanthorizons.core.render.renderer.DebugRenderer;
|
||||
import com.seibel.distanthorizons.core.sql.dto.BeaconBeamDTO;
|
||||
import com.seibel.distanthorizons.core.sql.repo.AbstractDhRepo;
|
||||
import com.seibel.distanthorizons.core.util.TimerUtil;
|
||||
import com.seibel.distanthorizons.core.util.objects.Pair;
|
||||
import com.seibel.distanthorizons.core.util.threading.ThreadPoolUtil;
|
||||
@@ -97,6 +98,8 @@ public class SharedApi
|
||||
ThreadPoolUtil.shutdownThreadPools();
|
||||
DebugRenderer.clearRenderables();
|
||||
MC_RENDER.clearTargetFrameBuffer();
|
||||
// shouldn't be necessary, but if we missed closing one of the connections this should make sure they're all closed
|
||||
AbstractDhRepo.closeAllConnections();
|
||||
// needs to be closed on world shutdown to clear out un-processed chunks
|
||||
UPDATING_CHUNK_POS_SET.clear();
|
||||
|
||||
|
||||
@@ -260,6 +260,18 @@ public abstract class AbstractDhLevel implements IDhLevel
|
||||
//================//
|
||||
|
||||
@Override
|
||||
public void close() { this.chunkToLodBuilder.close(); }
|
||||
public void close()
|
||||
{
|
||||
this.chunkToLodBuilder.close();
|
||||
|
||||
if (this.chunkHashRepo != null)
|
||||
{
|
||||
this.chunkHashRepo.close();
|
||||
}
|
||||
if (this.beaconBeamRepo != null)
|
||||
{
|
||||
this.beaconBeamRepo.close();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -426,6 +426,36 @@ public abstract class AbstractDhRepo<TKey, TDTO extends IBaseDTO<TKey>> implemen
|
||||
}
|
||||
}
|
||||
|
||||
/** can be used to make sure everything is closed when the world closes */
|
||||
public static void closeAllConnections()
|
||||
{
|
||||
LOGGER.info("Closing all ["+ACTIVE_CONNECTION_STRINGS_BY_REPO.size()+"] database connections...");
|
||||
for (String connectionString : ACTIVE_CONNECTION_STRINGS_BY_REPO.values())
|
||||
{
|
||||
try
|
||||
{
|
||||
Connection connection = CONNECTIONS_BY_CONNECTION_STRING.remove(connectionString);
|
||||
if (connection != null)
|
||||
{
|
||||
if (!connection.isClosed())
|
||||
{
|
||||
LOGGER.info("Closing database connection: [" + connectionString + "]");
|
||||
connection.close();
|
||||
}
|
||||
else
|
||||
{
|
||||
LOGGER.warn("Attempting to close already closed database connection: [" + connectionString + "]");
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(SQLException e)
|
||||
{
|
||||
// connection close failed.
|
||||
LOGGER.error("Unable to close the connection ["+connectionString+"], error: ["+e.getMessage()+"]");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user