Categories:
Audio (13)
Biotech (29)
Bytecode (36)
Database (77)
Framework (7)
Game (7)
General (507)
Graphics (53)
I/O (35)
IDE (2)
JAR Tools (101)
JavaBeans (21)
JDBC (121)
JDK (426)
JSP (20)
Logging (108)
Mail (58)
Messaging (8)
Network (84)
PDF (97)
Report (7)
Scripting (84)
Security (32)
Server (121)
Servlet (26)
SOAP (24)
Testing (54)
Web (15)
XML (309)
Collections:
Other Resources:
Source Code for Apache Log4j Core Implementation
Apache Log4j Core Implementation
provides the functional components of the logging system. Users are free to
create their own plugins and include them in the logging configuration.
Apache Log4j Core is a required module to use Apache Log4j.
Bytecode (Java 8) for Apache Log4j Core Implementation is provided in a separate JAR file like log4j-core-2.14.1.jar.
Source Code files for Apache Log4j API are provided in both binary packge like apache-log4j-2.14.1-bin.zip and source package like apache-log4j-2.14.1-src.zip. You can download them at Apache Log4j Website.
You can also browse Source Code files for Apache Log4j Core Implementation 2.14.1 below.
✍: FYIcenter.com
⏎ org/apache/logging/log4j/core/async/JCToolsBlockingQueueFactory.java
/* * 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.logging.log4j.core.async; import java.util.Collection; import java.util.concurrent.BlockingQueue; import java.util.concurrent.TimeUnit; import java.util.concurrent.locks.LockSupport; import org.apache.logging.log4j.core.config.Node; import org.apache.logging.log4j.core.config.plugins.Plugin; import org.apache.logging.log4j.core.config.plugins.PluginAttribute; import org.apache.logging.log4j.core.config.plugins.PluginFactory; import org.jctools.queues.MpscArrayQueue; /** * Factory for creating instances of BlockingQueues backed by JCTools {@link MpscArrayQueue}. * * @since 2.7 */ @Plugin(name = "JCToolsBlockingQueue", category = Node.CATEGORY, elementType = BlockingQueueFactory.ELEMENT_TYPE) public class JCToolsBlockingQueueFactory<E> implements BlockingQueueFactory<E> { private final WaitStrategy waitStrategy; private JCToolsBlockingQueueFactory(final WaitStrategy waitStrategy) { this.waitStrategy = waitStrategy; } @Override public BlockingQueue<E> create(final int capacity) { return new MpscBlockingQueue<>(capacity, waitStrategy); } @PluginFactory public static <E> JCToolsBlockingQueueFactory<E> createFactory( @PluginAttribute(value = "WaitStrategy", defaultString = "PARK") final WaitStrategy waitStrategy) { return new JCToolsBlockingQueueFactory<>(waitStrategy); } /** * BlockingQueue wrapper for JCTools multiple producer single consumer array queue. */ private static final class MpscBlockingQueue<E> extends MpscArrayQueue<E> implements BlockingQueue<E> { private final JCToolsBlockingQueueFactory.WaitStrategy waitStrategy; MpscBlockingQueue(final int capacity, final JCToolsBlockingQueueFactory.WaitStrategy waitStrategy) { super(capacity); this.waitStrategy = waitStrategy; } @Override public int drainTo(final Collection<? super E> c) { return drainTo(c, capacity()); } @Override public int drainTo(final Collection<? super E> c, final int maxElements) { return drain(e -> c.add(e), maxElements); } @Override public boolean offer(final E e, final long timeout, final TimeUnit unit) throws InterruptedException { int idleCounter = 0; final long timeoutNanos = System.nanoTime() + unit.toNanos(timeout); do { if (offer(e)) { return true; } else if (System.nanoTime() - timeoutNanos > 0) { return false; } idleCounter = waitStrategy.idle(idleCounter); } while (!Thread.interrupted()); //clear interrupted flag throw new InterruptedException(); } @Override public E poll(final long timeout, final TimeUnit unit) throws InterruptedException { int idleCounter = 0; final long timeoutNanos = System.nanoTime() + unit.toNanos(timeout); do { final E result = poll(); if (result != null) { return result; } else if (System.nanoTime() - timeoutNanos > 0) { return null; } idleCounter = waitStrategy.idle(idleCounter); } while (!Thread.interrupted()); //clear interrupted flag throw new InterruptedException(); } @Override public void put(final E e) throws InterruptedException { int idleCounter = 0; do { if (offer(e)) { return; } idleCounter = waitStrategy.idle(idleCounter); } while (!Thread.interrupted()); //clear interrupted flag throw new InterruptedException(); } @Override public boolean offer(final E e) { //keep 2 cache lines empty to avoid false sharing that will slow the consumer thread when queue is full. return offerIfBelowThreshold(e, capacity() - 32); } @Override public int remainingCapacity() { return capacity() - size(); } @Override public E take() throws InterruptedException { int idleCounter = 100; do { final E result = relaxedPoll(); if (result != null) { return result; } idleCounter = waitStrategy.idle(idleCounter); } while (!Thread.interrupted()); //clear interrupted flag throw new InterruptedException(); } } public enum WaitStrategy { SPIN(idleCounter -> idleCounter + 1), YIELD(idleCounter -> { Thread.yield(); return idleCounter + 1; }), PARK(idleCounter -> { LockSupport.parkNanos(1L); return idleCounter + 1; }), PROGRESSIVE(idleCounter -> { if (idleCounter > 200) { LockSupport.parkNanos(1L); } else if (idleCounter > 100) { Thread.yield(); } return idleCounter + 1; }); private final Idle idle; private int idle(final int idleCounter) { return idle.idle(idleCounter); } WaitStrategy(final Idle idle) { this.idle = idle; } } private interface Idle { int idle(int idleCounter); } }
⏎ org/apache/logging/log4j/core/async/JCToolsBlockingQueueFactory.java
Or download all of them as a single archive file:
File name: log4j-core-2.14.1-sources.jar File size: 1281358 bytes Release date: 2021-03-06 Download
⇒ Source Code for Apache Log4j JDK Logging Adapter
⇐ Source Code for Apache Log4j API
2015-11-03, 74010👍, 0💬
Popular Posts:
JDK 11 java.management.jmod is the JMOD file for JDK 11 Management module. JDK 11 Management module ...
What is the dom\GetElementsByTagName .javaprovided in the Apache Xerces package? I have Apache Xerce...
What Is poi-5.2.3.jar? poi-5.2.3.jar is one of the JAR files for Apache POI 5.2.3, which provides an...
What Is log4j-1.2.15.jar? I got the JAR file from apache-log4j-1.2.15.zip. log4j-1.2.15.jar is the v...
What Is jtds-1.2.2.jar? jtds-1.2.2.jar is the JAR files of jTDS Java library 1.2.2, which is a JDBC ...