-
Notifications
You must be signed in to change notification settings - Fork 793
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
optimize dubbo threadpool, add eager mode
- Loading branch information
1 parent
0b11401
commit 40d3738
Showing
2 changed files
with
84 additions
and
4 deletions.
There are no files selected for viewing
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
68 changes: 68 additions & 0 deletions
68
...rc/main/java/org/dromara/dynamictp/adapter/dubbo/apache/EagerThreadPoolExecutorProxy.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,68 @@ | ||
package org.dromara.dynamictp.adapter.dubbo.apache; | ||
|
||
import org.apache.dubbo.common.threadpool.support.eager.EagerThreadPoolExecutor; | ||
import org.apache.dubbo.common.threadpool.support.eager.TaskQueue; | ||
import org.dromara.dynamictp.core.aware.AwareManager; | ||
import org.dromara.dynamictp.core.aware.RejectHandlerAware; | ||
import org.dromara.dynamictp.core.aware.TaskEnhanceAware; | ||
import org.dromara.dynamictp.core.reject.RejectHandlerGetter; | ||
import org.dromara.dynamictp.core.support.task.wrapper.TaskWrapper; | ||
|
||
import java.util.List; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
/** | ||
* EagerThreadPoolExecutorProxy related | ||
* | ||
* @author yanhom | ||
* @since 1.1.5 | ||
*/ | ||
public class EagerThreadPoolExecutorProxy extends EagerThreadPoolExecutor implements TaskEnhanceAware, RejectHandlerAware { | ||
|
||
/** | ||
* Task wrappers, do sth enhanced. | ||
*/ | ||
private List<TaskWrapper> taskWrappers; | ||
|
||
private final String rejectHandlerType; | ||
|
||
public EagerThreadPoolExecutorProxy(EagerThreadPoolExecutor executor) { | ||
super(executor.getCorePoolSize(), executor.getMaximumPoolSize(), | ||
executor.getKeepAliveTime(TimeUnit.MILLISECONDS), | ||
TimeUnit.MILLISECONDS, (TaskQueue<Runnable>) executor.getQueue(), | ||
executor.getThreadFactory(), executor.getRejectedExecutionHandler()); | ||
this.rejectHandlerType = getRejectedExecutionHandler().getClass().getSimpleName(); | ||
setRejectedExecutionHandler(RejectHandlerGetter.getProxy(getRejectedExecutionHandler())); | ||
((TaskQueue<Runnable>) getQueue()).setExecutor(this); | ||
executor.shutdownNow(); | ||
} | ||
|
||
@Override | ||
public void execute(Runnable command) { | ||
command = getEnhancedTask(command, taskWrappers); | ||
AwareManager.execute(this, command); | ||
super.execute(command); | ||
} | ||
|
||
@Override | ||
protected void beforeExecute(Thread t, Runnable r) { | ||
super.beforeExecute(t, r); | ||
AwareManager.beforeExecute(this, t, r); | ||
} | ||
|
||
@Override | ||
protected void afterExecute(Runnable r, Throwable t) { | ||
super.afterExecute(r, t); | ||
AwareManager.afterExecute(this, r, t); | ||
} | ||
|
||
@Override | ||
public void setTaskWrappers(List<TaskWrapper> taskWrappers) { | ||
this.taskWrappers = taskWrappers; | ||
} | ||
|
||
@Override | ||
public String getRejectHandlerType() { | ||
return rejectHandlerType; | ||
} | ||
} |