All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.eclipse.jetty.util.thread.NonBlockingThread Maven / Gradle / Ivy

Go to download

A-Jetty Base can run on Android Java as well as on standard Java 7+ and it can run precompiled JSP/JSTL.

There is a newer version: 1.0.5
Show newest version
//
//  ========================================================================
//  Copyright (c) 1995-2016 Mort Bay Consulting Pty. Ltd.
//  ------------------------------------------------------------------------
//  All rights reserved. This program and the accompanying materials
//  are made available under the terms of the Eclipse Public License v1.0
//  and Apache License v2.0 which accompanies this distribution.
//
//      The Eclipse Public License is available at
//      http://www.eclipse.org/legal/epl-v10.html
//
//      The Apache License v2.0 is available at
//      http://www.opensource.org/licenses/apache2.0.php
//
//  You may elect to redistribute this code under either of these licenses.
//  ========================================================================
//

package org.eclipse.jetty.util.thread;

/**
 * Marker that wraps a Runnable, indicating that it is running in a thread that must not be blocked.
 * 

* Client code can use the thread-local {@link #isNonBlockingThread()} to detect whether they are * in the context of a non-blocking thread, and perform different actions if that's the case. */ public class NonBlockingThread implements Runnable { private final static ThreadLocal __nonBlockingThread = new ThreadLocal<>(); /** * @return whether the current thread is a thread that must not block. */ public static boolean isNonBlockingThread() { return Boolean.TRUE.equals(__nonBlockingThread.get()); } private final Runnable delegate; public NonBlockingThread(Runnable delegate) { this.delegate = delegate; } @Override public void run() { try { __nonBlockingThread.set(Boolean.TRUE); delegate.run(); } finally { __nonBlockingThread.set(Boolean.FALSE); } } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy