-
Notifications
You must be signed in to change notification settings - Fork 584
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix issue #280 thread renaming for ScheduledThreadPoolExecutor
- Loading branch information
1 parent
5c73ac7
commit eeb29a6
Showing
2 changed files
with
228 additions
and
6 deletions.
There are no files selected for viewing
168 changes: 168 additions & 0 deletions
168
...ad/src/main/java/com/didiglobal/booster/instrument/ShadowScheduledThreadPoolExecutor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,168 @@ | ||
package com.didiglobal.booster.instrument; | ||
|
||
import java.util.concurrent.RejectedExecutionHandler; | ||
import java.util.concurrent.ScheduledThreadPoolExecutor; | ||
import java.util.concurrent.ThreadFactory; | ||
|
||
/** | ||
* @author johnsonlee | ||
*/ | ||
public class ShadowScheduledThreadPoolExecutor extends ScheduledThreadPoolExecutor { | ||
|
||
/** | ||
* Initialize {@code ScheduledThreadPoolExecutor} with new thread name, this constructor is used by {@code ThreadTransformer} for thread renaming | ||
* | ||
* @param corePoolSize the number of threads to keep in the pool, even if they are idle, | ||
* unless {@code allowCoreThreadTimeOut} is set | ||
* @param prefix the prefix of new thread | ||
* @throws IllegalArgumentException if {@code corePoolSize < 0} | ||
*/ | ||
public ShadowScheduledThreadPoolExecutor( | ||
final int corePoolSize, | ||
final String prefix | ||
) { | ||
this(corePoolSize, prefix, false); | ||
} | ||
|
||
/** | ||
* Initialize {@code ScheduledThreadPoolExecutor} with new thread name, this constructor is used by {@code ThreadTransformer} for thread renaming | ||
* | ||
* @param corePoolSize the number of threads to keep in the pool, even if they are idle, | ||
* unless {@code allowCoreThreadTimeOut} is set | ||
* @param prefix the prefix of new thread | ||
* @param optimize the value indicates that the thread pool optimization should be applied | ||
* @throws IllegalArgumentException if {@code corePoolSize < 0} | ||
*/ | ||
public ShadowScheduledThreadPoolExecutor( | ||
final int corePoolSize, | ||
final String prefix, | ||
final boolean optimize | ||
) { | ||
super(corePoolSize, new NamedThreadFactory(prefix)); | ||
if (optimize) { | ||
allowCoreThreadTimeOut(true); | ||
} | ||
} | ||
|
||
/** | ||
* Initialize {@code ScheduledThreadPoolExecutor} with new thread name, this constructor is used by {@code ThreadTransformer} for thread renaming | ||
* | ||
* @param corePoolSize the number of threads to keep in the pool, even if they are idle, | ||
* unless {@code allowCoreThreadTimeOut} is set | ||
* @param threadFactory the factory to use when the executor creates a new thread | ||
* @param prefix the prefix of new thread | ||
* @throws IllegalArgumentException if {@code corePoolSize < 0} | ||
*/ | ||
public ShadowScheduledThreadPoolExecutor( | ||
final int corePoolSize, | ||
final ThreadFactory threadFactory, | ||
final String prefix | ||
) { | ||
this(corePoolSize, threadFactory, prefix, false); | ||
} | ||
|
||
/** | ||
* Initialize {@code ScheduledThreadPoolExecutor} with new thread name, this constructor is used by {@code ThreadTransformer} for thread renaming | ||
* | ||
* @param corePoolSize the number of threads to keep in the pool, even if they are idle, | ||
* unless {@code allowCoreThreadTimeOut} is set | ||
* @param threadFactory the factory to use when the executor creates a new thread | ||
* @param prefix the prefix of new thread | ||
* @param optimize the value indicates that the thread pool optimization should be applied | ||
* @throws IllegalArgumentException if {@code corePoolSize < 0} | ||
*/ | ||
public ShadowScheduledThreadPoolExecutor( | ||
final int corePoolSize, | ||
final ThreadFactory threadFactory, | ||
final String prefix, | ||
final boolean optimize | ||
) { | ||
super(corePoolSize, new NamedThreadFactory(threadFactory, prefix)); | ||
if (optimize) { | ||
allowCoreThreadTimeOut(true); | ||
} | ||
} | ||
|
||
/** | ||
* Initialize {@code ScheduledThreadPoolExecutor} with new thread name, this constructor is used by {@code ThreadTransformer} for thread renaming | ||
* | ||
* @param corePoolSize the number of threads to keep in the pool, even if they are idle, | ||
* unless {@code allowCoreThreadTimeOut} is set | ||
* @param handler the handler to use when execution is blocked because the thread bounds and queue capacities are reached | ||
* @param prefix the prefix of new thread | ||
* @throws IllegalArgumentException if {@code corePoolSize < 0} | ||
*/ | ||
public ShadowScheduledThreadPoolExecutor( | ||
final int corePoolSize, | ||
final RejectedExecutionHandler handler, | ||
final String prefix | ||
) { | ||
this(corePoolSize, handler, prefix, false); | ||
} | ||
|
||
/** | ||
* Initialize {@code ScheduledThreadPoolExecutor} with new thread name, this constructor is used by {@code ThreadTransformer} for thread renaming | ||
* | ||
* @param corePoolSize the number of threads to keep in the pool, even if they are idle, | ||
* unless {@code allowCoreThreadTimeOut} is set | ||
* @param handler the handler to use when execution is blocked because the thread bounds and queue capacities are reached | ||
* @param prefix the prefix of new thread | ||
* @param optimize the value indicates that the thread pool optimization should be applied | ||
* @throws IllegalArgumentException if {@code corePoolSize < 0} | ||
*/ | ||
public ShadowScheduledThreadPoolExecutor( | ||
final int corePoolSize, | ||
final RejectedExecutionHandler handler, | ||
final String prefix, | ||
final boolean optimize | ||
) { | ||
super(corePoolSize, new NamedThreadFactory(prefix), handler); | ||
if (optimize) { | ||
allowCoreThreadTimeOut(true); | ||
} | ||
} | ||
|
||
/** | ||
* Initialize {@code ScheduledThreadPoolExecutor} with new thread name, this constructor is used by {@code ThreadTransformer} for thread renaming | ||
* | ||
* @param corePoolSize the number of threads to keep in the pool, even if they are idle, | ||
* unless {@code allowCoreThreadTimeOut} is set | ||
* @param threadFactory the factory to use when the executor creates a new thread | ||
* @param handler the handler to use when execution is blocked because the thread bounds and queue capacities are reached | ||
* @param prefix the prefix of new thread | ||
* @throws IllegalArgumentException if {@code corePoolSize < 0} | ||
*/ | ||
public ShadowScheduledThreadPoolExecutor( | ||
final int corePoolSize, | ||
final ThreadFactory threadFactory, | ||
final RejectedExecutionHandler handler, | ||
final String prefix | ||
) { | ||
this(corePoolSize, threadFactory, handler, prefix, false); | ||
} | ||
|
||
/** | ||
* Initialize {@code ScheduledThreadPoolExecutor} with new thread name, this constructor is used by {@code ThreadTransformer} for thread renaming | ||
* | ||
* @param corePoolSize the number of threads to keep in the pool, even if they are idle, | ||
* unless {@code allowCoreThreadTimeOut} is set | ||
* @param threadFactory the factory to use when the executor creates a new thread | ||
* @param handler the handler to use when execution is blocked because the thread bounds and queue capacities are reached | ||
* @param prefix the prefix of new thread | ||
* @param optimize the value indicates that the thread pool optimization should be applied | ||
* @throws IllegalArgumentException if {@code corePoolSize < 0} | ||
*/ | ||
public ShadowScheduledThreadPoolExecutor( | ||
final int corePoolSize, | ||
final ThreadFactory threadFactory, | ||
final RejectedExecutionHandler handler, | ||
final String prefix, | ||
final boolean optimize | ||
) { | ||
super(corePoolSize, new NamedThreadFactory(threadFactory, prefix), handler); | ||
if (optimize) { | ||
allowCoreThreadTimeOut(true); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters