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

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

      
    
Rootfs path

      
    
Size
3341 (3.3 KB)
MD5
5c7b98c40b16fb0048c69d4619dbc6da
SHA1
20d13fc23f5a7c7fdec8a82dd537485dafb286a4
SHA256
a8b818c8238f0647c0321f78e42b7d5af12bf7667df8d579b0653ab42a8a4a46
SHA512

      
    
SHA1_git
92bf59bae14127f1446c28a5a23213b6ecb3d878
Is binary

      
    
Is text
True
Is archive

      
    
Is media

      
    
Is legal

      
    
Is manifest

      
    
Is readme

      
    
Is top level

      
    
Is key file

      
    
TesterPerformanceSynchronizedQueue.java | 3.3 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; import java.util.Queue; import java.util.concurrent.ConcurrentLinkedQueue; import org.junit.Test; public class TesterPerformanceSynchronizedQueue { private static final int THREAD_COUNT = 4; private static final int ITERATIONS = 1000000; private static final SynchronizedQueue<Object> S_QUEUE = new SynchronizedQueue<>(); private static final Queue<Object> QUEUE = new ConcurrentLinkedQueue<>(); @Test public void testSynchronizedQueue() throws InterruptedException { Thread[] threads = new Thread[THREAD_COUNT]; for (int i = 0; i < THREAD_COUNT; i++) { threads[i] = new StackThread(); } long start = System.currentTimeMillis(); for (int i = 0; i < THREAD_COUNT; i++) { threads[i].start(); } for (int i = 0; i < THREAD_COUNT; i++) { threads[i].join(); } long end = System.currentTimeMillis(); System.out.println("SynchronizedQueue: " + (end - start) + "ms"); } public static class StackThread extends Thread { @Override public void run() { for(int i = 0; i < ITERATIONS; i++) { Object obj = S_QUEUE.poll(); if (obj == null) { obj = new Object(); } S_QUEUE.offer(obj); } super.run(); } } @Test public void testConcurrentQueue() throws InterruptedException { Thread[] threads = new Thread[THREAD_COUNT]; for (int i = 0; i < THREAD_COUNT; i++) { threads[i] = new QueueThread(); } long start = System.currentTimeMillis(); for (int i = 0; i < THREAD_COUNT; i++) { threads[i].start(); } for (int i = 0; i < THREAD_COUNT; i++) { threads[i].join(); } long end = System.currentTimeMillis(); System.out.println("ConcurrentLinkedQueue: " + (end - start) + "ms"); } public static class QueueThread extends Thread { @Override public void run() { for(int i = 0; i < ITERATIONS; i++) { Object obj = QUEUE.poll(); if (obj == null) { obj = new Object(); } QUEUE.offer(obj); } super.run(); } } }
Detected license expression
apache-2.0
Detected license expression (SPDX)
Apache-2.0
Percentage of license text
33.43
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