He-Pin commented on code in PR #1724: URL: https://github.com/apache/pekko/pull/1724#discussion_r1920848176
########## actor/src/main/scala/org/apache/pekko/dispatch/VirtualThreadSupportReflect.scala: ########## @@ -0,0 +1,66 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.pekko.dispatch + +import org.apache.pekko.annotation.InternalApi + +import java.util.concurrent.{ ExecutorService, ThreadFactory } +import scala.util.control.NonFatal + +/** + * TODO remove this class once we drop Java 8 support + */ +@InternalApi +private[dispatch] object VirtualThreadSupportReflect { + + /** + * Create a virtual thread factory with given executor, the executor will be used as the scheduler of + * virtual thread. + * + * The executor should run task on platform threads. + * + * returns null if not supported. + */ + def newThreadPerTaskExecutor(prefix: String, executor: ExecutorService): ExecutorService = { + require(VirtualThreadSupport.isSupported, "Virtual thread is not supported.") + val factory = virtualThreadFactory(prefix, executor) + VirtualThreadSupport.newThreadPerTaskExecutor(factory) + } + + private def virtualThreadFactory(prefix: String, executor: ExecutorService): ThreadFactory = + try { + val builderClass = ClassLoader.getSystemClassLoader.loadClass("java.lang.Thread$Builder") Review Comment: @pjfanning @raboof Feel free to take care of this PR, I can live with the add opens, I hate Java 8. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@pekko.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: notifications-unsubscr...@pekko.apache.org For additional commands, e-mail: notifications-h...@pekko.apache.org