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

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

      
    
Rootfs path

      
    
Size
3333 (3.3 KB)
MD5
329a2b750b20c6998c54b314ee4e9e60
SHA1
447a771ace282041c25129d658fad467eae3279f
SHA256
9446d6fa8ed792fc2652675fafabeb9124bc1cd284ccdb35052afca0bfcbe15a
SHA512

      
    
SHA1_git
6979b3be06f37a6327eda74fac6a0b13cd51e933
Is binary

      
    
Is text
True
Is archive

      
    
Is media

      
    
Is legal

      
    
Is manifest

      
    
Is readme

      
    
Is top level

      
    
Is key file

      
    
TesterPerformanceSynchronizedStack.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 TesterPerformanceSynchronizedStack { private static final int THREAD_COUNT = 4; private static final int ITERATIONS = 1000000; private static final SynchronizedStack<Object> STACK = new SynchronizedStack<>(); private static final Queue<Object> QUEUE = new ConcurrentLinkedQueue<>(); @Test public void testSynchronizedStack() 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("SynchronizedStack: " + (end - start) + "ms"); } public static class StackThread extends Thread { @Override public void run() { for(int i = 0; i < ITERATIONS; i++) { Object obj = STACK.pop(); if (obj == null) { obj = new Object(); } STACK.push(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.71
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