Package org.bitcoinj.utils
Class Threading
- java.lang.Object
- 
- org.bitcoinj.utils.Threading
 
- 
 public class Threading extends java.lang.ObjectVarious threading related utilities. Provides a wrapper around explicit lock creation that lets you control whether bitcoinj performs cycle detection or not. Cycle detection is useful to detect bugs but comes with a small cost. Also provides a worker thread that is designed for event listeners to be dispatched on.
- 
- 
Nested Class SummaryNested Classes Modifier and Type Class Description static classThreading.UserThread
 - 
Field SummaryFields Modifier and Type Field Description static com.google.common.util.concurrent.CycleDetectingLockFactoryfactorystatic java.util.concurrent.ExecutorSAME_THREADA dummy executor that just invokes the runnable immediately.static java.util.concurrent.ExecutorServiceTHREAD_POOLA caching thread pool that creates daemon threads, which won't keep the JVM alive waiting for more work.static java.lang.Thread.UncaughtExceptionHandleruncaughtExceptionHandlerAn exception handler that will be invoked for any exceptions that occur in the user thread, and any unhandled exceptions that are caught whilst the framework is processing network traffic or doing other background tasks.static java.util.concurrent.ExecutorUSER_THREADAn executor with one thread that is intended for running event listeners on.
 - 
Constructor SummaryConstructors Constructor Description Threading()
 - 
Method SummaryAll Methods Static Methods Concrete Methods Modifier and Type Method Description static com.google.common.util.concurrent.CycleDetectingLockFactory.PolicygetPolicy()static voidignoreLockCycles()static java.util.concurrent.locks.ReentrantLocklock(java.lang.Class clazz)static java.util.concurrent.locks.ReentrantLocklock(java.lang.String name)static voidsetPolicy(com.google.common.util.concurrent.CycleDetectingLockFactory.Policy policy)static voidthrowOnLockCycles()static voidwaitForUserCode()Put a dummy task into the queue and wait for it to be run.static voidwarnOnLockCycles()
 
- 
- 
- 
Field Detail- 
USER_THREADpublic static java.util.concurrent.Executor USER_THREAD An executor with one thread that is intended for running event listeners on. This ensures all event listener code runs without any locks being held. It's intended for the API user to run things on. Callbacks registered by bitcoinj internally shouldn't normally run here, although currently there are a few exceptions.
 - 
SAME_THREADpublic static final java.util.concurrent.Executor SAME_THREAD A dummy executor that just invokes the runnable immediately. Use this over more complex executors (e.g. those extendingExecutorService), which are overkill for our needs.
 - 
uncaughtExceptionHandler@Nullable public static volatile java.lang.Thread.UncaughtExceptionHandler uncaughtExceptionHandler An exception handler that will be invoked for any exceptions that occur in the user thread, and any unhandled exceptions that are caught whilst the framework is processing network traffic or doing other background tasks. The purpose of this is to allow you to report back unanticipated crashes from your users to a central collection center for analysis and debugging. You should configure this before any bitcoinj library code is run, setting it after you started network traffic and other forms of processing may result in the change not taking effect.
 - 
factorypublic static com.google.common.util.concurrent.CycleDetectingLockFactory factory 
 - 
THREAD_POOLpublic static java.util.concurrent.ExecutorService THREAD_POOL A caching thread pool that creates daemon threads, which won't keep the JVM alive waiting for more work.
 
- 
 - 
Method Detail- 
waitForUserCodepublic static void waitForUserCode() Put a dummy task into the queue and wait for it to be run. Because it's single threaded, this means all tasks submitted before this point are now completed. Usually you won't want to use this method - it's a convenience primarily used in unit testing. If you want to wait for an event to be called the right thing to do is usually to create aCompletableFutureand then callCompletableFuture.complete(Object)on it. For example:
 You can then either block on that future, compose it, add listeners to it and so on.CompletableFuture f = CompletableFuture.supplyAsync(() -> event, USER_THREAD)
 - 
lockpublic static java.util.concurrent.locks.ReentrantLock lock(java.lang.Class clazz) 
 - 
lockpublic static java.util.concurrent.locks.ReentrantLock lock(java.lang.String name) 
 - 
warnOnLockCyclespublic static void warnOnLockCycles() 
 - 
throwOnLockCyclespublic static void throwOnLockCycles() 
 - 
ignoreLockCyclespublic static void ignoreLockCycles() 
 - 
setPolicypublic static void setPolicy(com.google.common.util.concurrent.CycleDetectingLockFactory.Policy policy) 
 - 
getPolicypublic static com.google.common.util.concurrent.CycleDetectingLockFactory.Policy getPolicy() 
 
- 
 
-