Return the thread local byte buffer. - Java java.nio

Java examples for java.nio:ByteBuffer Read

Description

Return the thread local byte buffer.

Demo Code

/*/*  w w  w . j  a  v a 2 s . c  om*/
Pulsar
Copyright (C) 2013-2015 eBay Software Foundation
Licensed under the GPL v2 license.  See LICENSE for full terms.
 */
//package com.java2s;
import java.nio.ByteBuffer;

public class Main {
    public static void main(String[] argv) throws Exception {
        System.out.println(getThreadLocalByteBuffer());
    }

    private static final ThreadLocal<ByteBuffer> TMP_BUFFER = new ThreadLocal<ByteBuffer>() {
        @Override
        protected ByteBuffer initialValue() {
            return ByteBuffer.allocate(4096);
        }
    };

    /**
     * Return the thread local byte buffer.
     * 
     * @return
     */
    public static ByteBuffer getThreadLocalByteBuffer() {
        return TMP_BUFFER.get();
    }
}

Related Tutorials