ttomcat-1778514358873.zip-extract/apache-tomcat-11.0.18-src/java/org/apache/tomcat/util/threads/VirtualThreadExecutor.java

Path
ttomcat-1778514358873.zip-extract/apache-tomcat-11.0.18-src/java/org/apache/tomcat/util/threads/VirtualThreadExecutor.java
Status
scanned
Type
file
Name
VirtualThreadExecutor.java
Extension
.java
Programming language
Java
Mime type
text/plain
File type
ASCII text, with CRLF line terminators
Tag

      
    
Rootfs path

      
    
Size
3299 (3.2 KB)
MD5
cff850a20d9621275c9824bb5787c4f1
SHA1
ef3dfa9dc16797a21bfb7a3f4251e51b1ea72db5
SHA256
f238492be75bf5ad8c67b145fbf6b0a204e7fa47ea5fa26fb457f1bf7ebf8aa2
SHA512

      
    
SHA1_git
87b6c4353ae29b9b61eb26b0b73c3543796152d9
Is binary

      
    
Is text
True
Is archive

      
    
Is media

      
    
Is legal

      
    
Is manifest

      
    
Is readme

      
    
Is top level

      
    
Is key file

      
    
VirtualThreadExecutor.java | 3.2 KB |

/* * 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.tomcat.util.threads; import java.util.Collections; import java.util.List; import java.util.concurrent.AbstractExecutorService; import java.util.concurrent.CountDownLatch; import java.util.concurrent.RejectedExecutionException; import java.util.concurrent.TimeUnit; import org.apache.tomcat.util.compat.JreCompat; import org.apache.tomcat.util.res.StringManager; /** * An executor that uses a new virtual thread for each task. */ public class VirtualThreadExecutor extends AbstractExecutorService { private static final StringManager sm = StringManager.getManager(VirtualThreadExecutor.class); private final CountDownLatch shutdown = new CountDownLatch(1); private final JreCompat jreCompat = JreCompat.getInstance(); private Object threadBuilder; public VirtualThreadExecutor(String namePrefix) { threadBuilder = jreCompat.createVirtualThreadBuilder(namePrefix); } @Override public void execute(Runnable command) { if (isShutdown()) { throw new RejectedExecutionException( sm.getString("virtualThreadExecutor.taskRejected", command.toString(), this.toString())); } jreCompat.threadBuilderStart(threadBuilder, command); } @Override public void shutdown() { shutdown.countDown(); } /** * {@inheritDoc} * <p> * The VirtualThreadExecutor does not track in-progress tasks so calling this method is equivalent to calling * {@link #shutdown()}. */ @Override public List<Runnable> shutdownNow() { shutdown(); return Collections.emptyList(); } @Override public boolean isShutdown() { return shutdown.getCount() == 0; } /** * {@inheritDoc} * <p> * The VirtualThreadExecutor does not track in-progress tasks so calling this method is equivalent to calling * {@link #isShutdown()}. */ @Override public boolean isTerminated() { return isShutdown(); } /** * {@inheritDoc} * <p> * The VirtualThreadExecutor does not track in-progress tasks so calling this method is effectively waiting for * {@link #shutdown()} to be called. */ @Override public boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException { return shutdown.await(timeout, unit); } }
Detected license expression
apache-2.0
Detected license expression (SPDX)
Apache-2.0
Percentage of license text
35.0
Copyrights

      
    
Holders

      
    
Authors

      
    
License detections License expression License expression SPDX
apache_2_0-4bde3f57-78aa-4201-96bf-531cba09e7de apache-2.0 Apache-2.0
URL Start line End line
http://www.apache.org/licenses/LICENSE-2.0 9 9