@Override
    public ApplicationLock lockApplication(OrchestratorContext context, ApplicationInstanceReference reference)
            throws UncheckedTimeoutException {

        Runnable onRegistryClose;

        // A multi-application operation, aka batch suspension, will first issue a probe
        // then a non-probe. With "large locks", the lock is not released in between -
        // no lock is taken on the non-probe. Instead, the release is done on the multi-application
        // context close.
        if (context.hasLock(reference)) {
            onRegistryClose = () -> {};
        } else {
            Runnable unlock = acquireLock(context, reference);
            if (context.registerLockAcquisition(reference, unlock)) {
                onRegistryClose = () -> {};
            } else {
                onRegistryClose = unlock;
            }
        }

        try {
            return new ZkApplicationLock(
                    this,
                    curator,
                    onRegistryClose,
                    reference,
                    context.isProbe(),
                    hostInfosCache);
        } catch (Throwable t) {
            // In case the constructor throws an exception.
            onRegistryClose.run();
            throw t;
        }
    }
1) locks the status service for an application instance.
 2) fails all operations in this thread when the session is lost,
    since session loss might cause the lock to be lost.
    Since it only fails operations in this thread,
    all operations depending on a lock, including the locking itself, must be done in this thread.
    Note that since it is the thread that fails, all status operations in this thread will fail
    even if they're not supposed to be guarded by this lock
    (i.e. the request is for another applicationInstanceReference)
orchestrator/src/main/java/com/yahoo/vespa/orchestrator/status/ZkStatusService.java