增加AnonymousVirtualExecutor
This commit is contained in:
@@ -565,7 +565,7 @@ public final class Application {
|
||||
if (workHash) {
|
||||
workExecutor0 = WorkThread.createHashExecutor(workThreads, "Redkale-HashWorkThread-%s");
|
||||
} else {
|
||||
workExecutor0 = WorkThread.createExecutor(workThreads, "Redkale-WorkThread-%s");
|
||||
workExecutor0 = WorkThread.createWorkExecutor(workThreads, "Redkale-WorkThread-%s");
|
||||
}
|
||||
}
|
||||
this.workExecutor = workExecutor0;
|
||||
@@ -575,7 +575,7 @@ public final class Application {
|
||||
ExecutorService clientExecutor = workExecutor0;
|
||||
if (clientExecutor == null) {
|
||||
//给所有client给一个默认的ExecutorService
|
||||
clientExecutor = WorkThread.createExecutor(executorConf.getIntValue("clients", Utility.cpus()), "Redkale-DefaultClient-WorkThread-%s");
|
||||
clientExecutor = WorkThread.createWorkExecutor(executorConf.getIntValue("clients", Utility.cpus()), "Redkale-DefaultClient-WorkThread-%s");
|
||||
}
|
||||
this.clientAsyncGroup = new AsyncIOGroup("Redkale-DefaultClient-IOThread-%s", clientExecutor, bufferCapacity, bufferPoolSize).skipClose(true);
|
||||
}
|
||||
|
||||
@@ -8,7 +8,8 @@ package org.redkale.net;
|
||||
import java.util.Collection;
|
||||
import java.util.concurrent.*;
|
||||
import java.util.concurrent.atomic.*;
|
||||
import org.redkale.util.ThreadHashExecutor;
|
||||
import java.util.function.Function;
|
||||
import org.redkale.util.*;
|
||||
|
||||
/**
|
||||
* 协议处理的自定义线程类
|
||||
@@ -58,6 +59,11 @@ public class WorkThread extends Thread implements Executor {
|
||||
});
|
||||
}
|
||||
|
||||
public static ExecutorService createWorkExecutor(final int threads, final String threadNameFormat) {
|
||||
final Function<String, ExecutorService> func = Utility.virtualExecutorFunction();
|
||||
return func == null ? createExecutor(threads, threadNameFormat) : func.apply(threadNameFormat);
|
||||
}
|
||||
|
||||
public static ExecutorService createExecutor(final int threads, final String threadNameFormat) {
|
||||
final AtomicReference<ExecutorService> ref = new AtomicReference<>();
|
||||
final AtomicInteger counter = new AtomicInteger();
|
||||
|
||||
@@ -291,7 +291,7 @@ public abstract class AbstractDataSource extends AbstractService implements Data
|
||||
executorLock.lock();
|
||||
try {
|
||||
if (this.sourceExecutor == null) {
|
||||
this.sourceExecutor = WorkThread.createExecutor(sourceThreads, "Redkale-DataSource-WorkThread-" + resourceName() + "-%s");
|
||||
this.sourceExecutor = WorkThread.createWorkExecutor(sourceThreads, "Redkale-DataSource-WorkThread-" + resourceName() + "-%s");
|
||||
}
|
||||
} finally {
|
||||
executorLock.unlock();
|
||||
|
||||
27
src/main/java/org/redkale/util/AnonymousVirtualExecutor.java
Normal file
27
src/main/java/org/redkale/util/AnonymousVirtualExecutor.java
Normal file
@@ -0,0 +1,27 @@
|
||||
///*
|
||||
// *
|
||||
// */
|
||||
//package org.redkale.util;
|
||||
//
|
||||
//import java.util.concurrent.*;
|
||||
//import java.util.concurrent.atomic.AtomicInteger;
|
||||
//import java.util.function.Function;
|
||||
//
|
||||
///**
|
||||
// *
|
||||
// * @author zhangjx
|
||||
// */
|
||||
//public class AnonymousVirtualExecutor implements Function<String, ExecutorService> {
|
||||
//
|
||||
// @Override
|
||||
// public ExecutorService apply(String threadNameFormat) {
|
||||
// final ThreadFactory factory = Thread.ofVirtual().factory();
|
||||
// final AtomicInteger counter = new AtomicInteger();
|
||||
// return Executors.newThreadPerTaskExecutor(r -> {
|
||||
// Thread t = factory.newThread(r);
|
||||
// int c = counter.incrementAndGet();
|
||||
// t.setName(String.format(threadNameFormat, "Virtual-" + (c < 10 ? ("00" + c) : (c < 100 ? ("0" + c) : c))));
|
||||
// return t;
|
||||
// });
|
||||
// }
|
||||
//}
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user