Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: virtual thread name #1393

Merged
merged 1 commit into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,8 @@ public class ThreadPoolConstant {
public static final String DEFAULT_THREAD_NAME_PREFIX = "SOFA-RPC-DEFAULT";
public static final String BIZ_THREAD_NAME_PREFIX = "SEV-BOLT-BIZ-";

public static final String TYPE_PREFIX_TREAD = "T";

public static final String TYPE_PREFIX_VIRTUAL_TREAD = "VT";

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@

import com.alipay.sofa.rpc.common.threadpool.SofaExecutorFactory;
import com.alipay.sofa.common.thread.virtual.SofaVirtualThreadFactory;
import com.alipay.sofa.rpc.common.threadpool.ThreadPoolConstant;
import com.alipay.sofa.rpc.config.ServerConfig;
import com.alipay.sofa.rpc.ext.Extension;

import java.util.concurrent.Executor;
import java.util.concurrent.atomic.AtomicInteger;

/**
*
Expand All @@ -31,9 +33,31 @@
@Extension(value = "virtual")
public class VirtualThreadPoolFactory implements SofaExecutorFactory {

/**
* 系统全局线程池计数器
*/
private static final AtomicInteger POOL_COUNT = new AtomicInteger();

@Override
public Executor createExecutor(String namePrefix, ServerConfig serverConfig) {
// virtual thread does not support any configs now
return SofaVirtualThreadFactory.ofExecutorService(namePrefix);
return SofaVirtualThreadFactory.ofExecutorService(buildNamePrefix(namePrefix));
}

/**
* refine virtual thread name
* SOFA-originInput-0-VT123
* @param namePrefix
* @return
*/
private String buildNamePrefix(String namePrefix) {
StringBuilder sb = new StringBuilder();
sb.append("SOFA-");
sb.append(namePrefix);
sb.append("-");
sb.append(POOL_COUNT.getAndIncrement());
sb.append("-");
sb.append(ThreadPoolConstant.TYPE_PREFIX_VIRTUAL_TREAD);
return sb.toString();
}
}
Loading