All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.yammer.metrics.util.DeadlockHealthCheck Maven / Gradle / Ivy

There is a newer version: 3.0.0-BETA1
Show newest version
package com.yammer.metrics.util;

import com.yammer.metrics.core.HealthCheck;
import com.yammer.metrics.core.VirtualMachineMetrics;

import java.util.Set;

/**
 * A {@link HealthCheck} implementation which returns a list of deadlocked threads, if any.
 */
public class DeadlockHealthCheck extends HealthCheck {
    private final VirtualMachineMetrics vm;

    /**
     * Creates a new {@link DeadlockHealthCheck} with the given {@link VirtualMachineMetrics}
     * instance.
     *
     * @param vm    a {@link VirtualMachineMetrics} instance
     */
    public DeadlockHealthCheck(VirtualMachineMetrics vm) {
        super("deadlocks");
        this.vm = vm;
    }

    /**
     * Creates a new {@link DeadlockHealthCheck}.
     */
    @SuppressWarnings("UnusedDeclaration")
    public DeadlockHealthCheck() {
        this(VirtualMachineMetrics.getInstance());
    }

    @Override
    protected Result check() throws Exception {
        final Set threads = vm.deadlockedThreads();
        if (threads.isEmpty()) {
            return Result.healthy();
        }

        final StringBuilder builder = new StringBuilder("Deadlocked threads detected:\n");
        for (String thread : threads) {
            builder.append(thread).append('\n');
        }
        return Result.unhealthy(builder.toString());
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy