Class TtlAgent
- java.lang.Object
-
- com.alibaba.ttl.threadpool.agent.TtlAgent
-
public final class TtlAgent extends Object
TTL Java Agent.The configuration/arguments for TTL agent
Configure TTL agent via agent arguments, format is
k1: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
ThreadFactory
constructor parameter ofThreadPoolExecutor
toDisableInheritableThreadFactory
by util methodgetDisableInheritableThreadFactory
. - rewrite the
ForkJoinPool.ForkJoinWorkerThreadFactory
constructor parameter ofForkJoinPool
toDisableInheritableForkJoinWorkerThreadFactory
by util methodgetDisableInheritableForkJoinWorkerThreadFactory
.
TransmittableThreadLocal
.Configuration example:
-javaagent:/path/to/transmittable-thread-local-2.x.x.jar=ttl.agent.disable.inheritable.for.thread.pool:true
The log configuration
The log of TTL Java Agent is config by keyttl.agent.logger
. Since version2.6.0
.ttl.agent.logger : STDERR
only log tostderr
when 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.2
the default value istrue
(enable TimerTask class decoration); Before version2.11.1
default 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
About boot classpath for TTL agent
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 classpath
manually by java option-Xbootclasspath/a:path/to/ttl-foo-name-changed.jar
.The implementation of auto adding self agent jar to
boot classpath
use theBoot-Class-Path
property 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-Path
see The mechanism for instrumentation.- Since:
- 0.9.0
- Author:
- Jerry Lee (oldratlee at gmail dot com)
- See Also:
Instrumentation
, The mechanism for instrumentation, JAR File Specification - JAR Manifest, Working with Manifest Files - The Java™ TutorialsHide,TransmittableThreadLocal
,ThreadPoolExecutor
,ScheduledThreadPoolExecutor
,ForkJoinPool
,TimerTask
- rewrite the
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static boolean
isDisableInheritableForThreadPool()
Whether disable inheritable for thread pool is enhanced by ttl agent, checkisTtlAgentLoaded()
first.static boolean
isEnableTimerTask()
Whether timer task is enhanced by ttl agent, checkisTtlAgentLoaded()
first.static boolean
isTtlAgentLoaded()
Whether TTL agent is loaded.static void
premain(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.- See Also:
Logger
,Logger.TTL_AGENT_LOGGER_KEY
,Logger.STDERR
,Logger.STDOUT
-
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
-
-