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

io.inugami.commons.threads.MonitoredThread Maven / Gradle / Ivy

There is a newer version: 3.3.5
Show newest version
package io.inugami.commons.threads;

import io.inugami.api.monitoring.MdcService;
import io.inugami.api.monitoring.MonitoringInitializer;
import io.inugami.api.monitoring.RequestContext;
import io.inugami.api.monitoring.RequestInformation;

import java.util.List;

@SuppressWarnings({"java:S3014"})
public class MonitoredThread extends Thread {

    // =========================================================================
    // ATTRIBUTES
    // =========================================================================
    private final RequestInformation requestContext;

    private final List monitoringInitializer;

    // =========================================================================
    // CONSTRUCTORS
    // =========================================================================
    public MonitoredThread(final ThreadGroup group, final Runnable target, final String name, final long stackSize,
                           final RequestInformation requestContext,
                           final List monitoringInitializer) {
        super(group, target, name, stackSize);
        this.requestContext = requestContext;
        this.monitoringInitializer = monitoringInitializer;
    }

    // =========================================================================
    // RUN
    // =========================================================================
    @Override
    public void run() {
        RequestContext.setInstance(requestContext);
        MdcService.getInstance().initialize();
        monitoringInitializer.forEach(MonitoringInitializer::initialize);
        super.run();
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy