Class TtlAgent
- java.lang.Object
-
- com.alibaba.ttl.threadpool.agent.TtlAgent
-
public final class TtlAgent extends Object
TTL Java Agent.The configuration/arguments for agent see the javadoc of
premain(String, Instrumentation)NOTE:
Sincev2.6.0, TTL agent jar will auto add self toboot classpath. But you should NOT modify the downloaded TTL jar file name in the maven repo(eg:transmittable-thread-local-2.x.x.jar).
if you modified the downloaded TTL agent jar file name(eg:ttl-foo-name-changed.jar), you must add TTL agent jar toboot classpathmanually by java option-Xbootclasspath/a:path/to/ttl-foo-name-changed.jar.The implementation of auto adding self agent jar to
boot classpathuse theBoot-Class-Pathproperty of manifest file(META-INF/MANIFEST.MF) in the TTL Java Agent Jar:- Boot-Class-Path
- A list of paths to be searched by the bootstrap class loader. Paths represent directories or libraries (commonly referred to as JAR or zip libraries on many platforms). These paths are searched by the bootstrap class loader after the platform specific mechanisms of locating a class have failed. Paths are searched in the order listed.
More info about
Boot-Class-Pathsee The mechanism for instrumentation.- Since:
- 0.9.0
- Author:
- Jerry Lee (oldratlee at gmail dot com)
- See Also:
TransmittableThreadLocal,Instrumentation, The mechanism for instrumentation, JAR File Specification - JAR Manifest, Working with Manifest Files - The Java™ TutorialsHide
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static booleanisDisableInheritableForThreadPool()Whether disable inheritable for thread pool is enhanced by ttl agent, checkisTtlAgentLoaded()first.static booleanisEnableTimerTask()Whether timer task is enhanced by ttl agent, checkisTtlAgentLoaded()first.static booleanisTtlAgentLoaded()Whether TTL agent is loaded.static voidpremain(String agentArgs, Instrumentation inst)Entrance method of TTL Java Agent.
-
-
-
Method Detail
-
premain
public static void premain(String agentArgs, @NonNull Instrumentation inst)
Entrance method of TTL Java Agent.TTL Agent configuration
Configure TTL agent via agent arguments, format isk1:v1,k2:v2. Below is available configuration keys.Disable inheritable for thread pool
Enable "disable inheritable" for thread pool, config by key
ttl.agent.disable.inheritable.for.thread.pool. When no configuration for this key, default does not enabled. Since version2.10.1.- rewrite the
ThreadFactoryconstructor parameter ofThreadPoolExecutortoDisableInheritableThreadFactoryby util methodTtlExecutors.getDisableInheritableThreadFactory(java.util.concurrent.ThreadFactory). - rewrite the
ForkJoinPool.ForkJoinWorkerThreadFactoryconstructor parameter ofForkJoinPooltoDisableInheritableForkJoinWorkerThreadFactoryby util methodTtlForkJoinPoolHelper.getDisableInheritableForkJoinWorkerThreadFactory(java.util.concurrent.ForkJoinPool.ForkJoinWorkerThreadFactory).
TransmittableThreadLocal.Configuration example:
-javaagent:/path/to/transmittable-thread-local-2.x.x.jar=ttl.agent.disable.inheritable.for.thread.pool:trueThe log configuration
The log of TTL Java Agent is config by keyttl.agent.logger. Since version2.6.0.ttl.agent.logger : STDERR
only log tostderrwhen error. This is default, when no/unrecognized configuration for keyttl.agent.logger.ttl.agent.logger : STDOUT
Log tostdout, more info thanttl.agent.logger:STDERR; This is needed when developing.
configuration example:
-javaagent:/path/to/transmittable-thread-local-2.x.x.jar-javaagent:/path/to/transmittable-thread-local-2.x.x.jar=ttl.agent.logger:STDOUT
Enable/disable TimerTask class decoration
Enable/disable TimerTask class decoration is config by keyttl.agent.enable.timer.task. Since version2.7.0.When no configuration for this key, default is enabled.
Note: Since version2.11.2the default value istrue(enable TimerTask class decoration); Before version2.11.1default value isfalse.Configuration example:
-javaagent:/path/to/transmittable-thread-local-2.x.x.jar=ttl.agent.enable.timer.task:false-javaagent:/path/to/transmittable-thread-local-2.x.x.jar=ttl.agent.enable.timer.task:true
Multi key configuration example
-javaagent:/path/to/transmittable-thread-local-2.x.x.jar=ttl.agent.logger:STDOUT,ttl.agent.disable.inheritable.for.thread.pool:true- See Also:
ThreadPoolExecutor,ScheduledThreadPoolExecutor,ForkJoinPool,TimerTask,Logger,Logger.TTL_AGENT_LOGGER_KEY,Logger.STDERR,Logger.STDOUT
- rewrite the
-
isTtlAgentLoaded
public static boolean isTtlAgentLoaded()
Whether TTL agent is loaded.- Since:
- 2.9.0
-
isDisableInheritableForThreadPool
public static boolean isDisableInheritableForThreadPool()
Whether disable inheritable for thread pool is enhanced by ttl agent, checkisTtlAgentLoaded()first.- Since:
- 2.10.1
- See Also:
TtlExecutors.getDefaultDisableInheritableThreadFactory(),TtlExecutors.getDisableInheritableThreadFactory(java.util.concurrent.ThreadFactory),DisableInheritableThreadFactory,TtlForkJoinPoolHelper.getDefaultDisableInheritableForkJoinWorkerThreadFactory(),TtlForkJoinPoolHelper.getDisableInheritableForkJoinWorkerThreadFactory(java.util.concurrent.ForkJoinPool.ForkJoinWorkerThreadFactory),DisableInheritableForkJoinWorkerThreadFactory
-
isEnableTimerTask
public static boolean isEnableTimerTask()
Whether timer task is enhanced by ttl agent, checkisTtlAgentLoaded()first.- Since:
- 2.10.1
-
-