|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one or more |
| 3 | + * contributor license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright ownership. |
| 5 | + * The ASF licenses this file to You under the Apache License, Version 2.0 |
| 6 | + * (the "License"); you may not use this file except in compliance with |
| 7 | + * the License. You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | +package com.alipay.sofa.common.thread.virtual; |
| 18 | + |
| 19 | +import java.util.concurrent.ExecutorService; |
| 20 | + |
| 21 | +/** |
| 22 | + * Delegate for virtual thread handling on JDK 21. |
| 23 | + * This is a dummy version for reachability on JDK less than 21. |
| 24 | + * |
| 25 | + * @author huzijie |
| 26 | + * @version SofaVirtualThreadFactory.java, v 0.1 2023年11月20日 3:57 PM huzijie Exp $ |
| 27 | + */ |
| 28 | +public class SofaVirtualThreadFactory { |
| 29 | + |
| 30 | + /** |
| 31 | + * Create a virtual thread with name. |
| 32 | + * |
| 33 | + * @param name thread name |
| 34 | + * @param runnable task to run with thread |
| 35 | + * @return a virtual thread with runnable |
| 36 | + * @since 2.1.0 |
| 37 | + */ |
| 38 | + public static Thread ofThread(String name, Runnable runnable) { |
| 39 | + throw new UnsupportedOperationException("Virtual threads not supported on JDK <21"); |
| 40 | + } |
| 41 | + |
| 42 | + /** |
| 43 | + * Create a virtual thread with name. |
| 44 | + * |
| 45 | + * @param name thread name |
| 46 | + * @param inheritInheritableThreadLocals {@code true} to inherit, {@code false} to not inherit |
| 47 | + * @param uncaughtExceptionHandler uncaught exception handler |
| 48 | + * @param runnable task to run with thread |
| 49 | + * @return a virtual thread with runnable |
| 50 | + * @since 2.1.0 |
| 51 | + */ |
| 52 | + |
| 53 | + public static Thread ofThread(String name, boolean inheritInheritableThreadLocals, |
| 54 | + Thread.UncaughtExceptionHandler uncaughtExceptionHandler, |
| 55 | + Runnable runnable) { |
| 56 | + throw new UnsupportedOperationException("Virtual threads not supported on JDK <21"); |
| 57 | + } |
| 58 | + |
| 59 | + /** |
| 60 | + * Creates an Executor that starts a new virtual Thread for each task. |
| 61 | + * The number of threads created by the Executor is unbounded. |
| 62 | + * |
| 63 | + * @param prefix thread prefix |
| 64 | + * @return a new executor that creates a new virtual Thread for each task |
| 65 | + * @since 2.1.0 |
| 66 | + */ |
| 67 | + public static ExecutorService ofExecutorService(String prefix) { |
| 68 | + throw new UnsupportedOperationException("Virtual threads not supported on JDK <21"); |
| 69 | + } |
| 70 | + |
| 71 | + /** |
| 72 | + * Creates an Executor that starts a new virtual Thread for each task. |
| 73 | + * The number of threads created by the Executor is unbounded. |
| 74 | + * |
| 75 | + * @param prefix thread prefix |
| 76 | + * @param start the starting value of the counter |
| 77 | + * @param inheritInheritableThreadLocals {@code true} to inherit, {@code false} to not inherit |
| 78 | + * @param uncaughtExceptionHandler uncaught exception handler |
| 79 | + * @return a new executor that creates a new virtual Thread for each task |
| 80 | + * @since 2.1.0 |
| 81 | + */ |
| 82 | + public static ExecutorService ofExecutorService(String prefix, |
| 83 | + long start, |
| 84 | + boolean inheritInheritableThreadLocals, |
| 85 | + Thread.UncaughtExceptionHandler uncaughtExceptionHandler) { |
| 86 | + throw new UnsupportedOperationException("Virtual threads not supported on JDK <21"); |
| 87 | + } |
| 88 | +} |
0 commit comments