ttomcat-1778514358873.zip-extract/apache-tomcat-11.0.18-src/java/org/apache/tomcat/util/collections/SynchronizedQueue.java

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

      
    
Rootfs path

      
    
Size
2967 (2.9 KB)
MD5
455441ca9e6a1121e92bce3f693b4351
SHA1
3172f69664d28d8552b6bbe0ceef008cefe26d48
SHA256
4fd932a1671849516469495b08f322d1edbbc0a8ed48a3f98ccf9ed52046229a
SHA512

      
    
SHA1_git
572a95c935546c9b2c97582ccdf55259624754e6
Is binary

      
    
Is text
True
Is archive

      
    
Is media

      
    
Is legal

      
    
Is manifest

      
    
Is readme

      
    
Is top level

      
    
Is key file

      
    
SynchronizedQueue.java | 2.9 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.collections; /** * This is intended as a (mostly) GC-free alternative to {@link java.util.concurrent.ConcurrentLinkedQueue} when the * requirement is to create an unbounded queue with no requirement to shrink the queue. The aim is to provide the bare * minimum of required functionality as quickly as possible with minimum garbage. * * @param <T> The type of object managed by this queue */ public class SynchronizedQueue<T> { public static final int DEFAULT_SIZE = 128; private Object[] queue; private int size; private int insert = 0; private int remove = 0; public SynchronizedQueue() { this(DEFAULT_SIZE); } public SynchronizedQueue(int initialSize) { queue = new Object[initialSize]; size = initialSize; } public synchronized boolean offer(T t) { queue[insert++] = t; // Wrap if (insert == size) { insert = 0; } if (insert == remove) { expand(); } return true; } public synchronized T poll() { if (insert == remove) { // empty return null; } @SuppressWarnings("unchecked") T result = (T) queue[remove]; queue[remove] = null; remove++; // Wrap if (remove == size) { remove = 0; } return result; } private void expand() { int newSize = size * 2; Object[] newQueue = new Object[newSize]; System.arraycopy(queue, insert, newQueue, 0, size - insert); System.arraycopy(queue, 0, newQueue, size - insert, insert); insert = size; remove = 0; queue = newQueue; size = newSize; } public synchronized int size() { int result = insert - remove; if (result < 0) { result += size; } return result; } public synchronized void clear() { queue = new Object[size]; insert = 0; remove = 0; } }
Detected license expression
apache-2.0
Detected license expression (SPDX)
Apache-2.0
Percentage of license text
35.52
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