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

com.alibaba.ttl.threadpool.agent.TtlAgent Maven / Gradle / Ivy

Go to download

a simple lib for transmitting ThreadLocal value between thread even using thread pool.

There is a newer version: 2.5.1
Show newest version
package com.alibaba.ttl.threadpool.agent;


import java.lang.instrument.ClassFileTransformer;
import java.lang.instrument.Instrumentation;
import java.util.logging.Logger;


/**
 * @author Jerry Lee (oldratlee at gmail dot com)
 * @see The mechanism for instrumentation
 * @since 0.9.0
 */
public final class TtlAgent {
    private static final Logger logger = Logger.getLogger(TtlAgent.class.getName());
    
    private TtlAgent() {
    	throw new InstantiationError( "Must not instantiate this class" );
    }
    
    public static void premain(String agentArgs, Instrumentation inst) {
        logger.info("[TtlAgent.premain] begin, agentArgs: " + agentArgs);
        install(agentArgs, inst);
    }

    static void install(String agentArgs, Instrumentation inst) {
        logger.info("[TtlAgent.install] agentArgs: " + agentArgs + ", Instrumentation: " + inst);

        ClassFileTransformer transformer = new TtlTransformer();
        inst.addTransformer(transformer, true);

        logger.info("[TtlAgent.install] addTransformer success.");
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy