class CommandExecutorTask implements Runnable {

    @Override
    public void run() {
        RootInvokeHook rootInvokeHook = new SPIRootInvokeHook();
        rootInvokeHook.start();
        boolean isNeedFlush = false;
        int connectionSize = 0;
        try (PacketPayload payload = databaseProtocolFrontendEngine.getCodecEngine().createPacketPayload((ByteBuf) message)) {
            ConnectionStatus connectionStatus = backendConnection.getConnectionStatus();
            if (!backendConnection.getTransactionStatus().isInConnectionHeldTransaction()) {
                connectionStatus.waitUntilConnectionRelease();
                connectionStatus.switchToUsing();
            }
            isNeedFlush = executeCommand(context, payload, backendConnection);
            connectionSize = backendConnection.getConnectionSize();
            // CHECKSTYLE:OFF
        } catch (final Exception ex) {
            // CHECKSTYLE:ON
            processException(ex);
        } finally {
            Collection<SQLException> exceptions = closeExecutionResources();
            if (isNeedFlush) {
                context.flush();
            }
            if (!backendConnection.getTransactionStatus().isInConnectionHeldTransaction()) {
                exceptions.addAll(backendConnection.closeConnections(false));
            }
            processClosedExceptions(exceptions);
            rootInvokeHook.finish(connectionSize);
        }
    }

}