Package org.greenrobot.eventbus
Enum ThreadMode
- java.lang.Object
-
- java.lang.Enum<ThreadMode>
-
- org.greenrobot.eventbus.ThreadMode
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Comparable<ThreadMode>
public enum ThreadMode extends java.lang.Enum<ThreadMode>
Each subscriber method has a thread mode, which determines in which thread the method is to be called by EventBus. EventBus takes care of threading independently of the posting thread.- See Also:
EventBus.register(Object)
-
-
Enum Constant Summary
Enum Constants Enum Constant Description ASYNC
Subscriber will be called in a separate thread.BACKGROUND
On Android, subscriber will be called in a background thread.MAIN
On Android, subscriber will be called in Android's main thread (UI thread).MAIN_ORDERED
On Android, subscriber will be called in Android's main thread (UI thread).POSTING
This is the default.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static ThreadMode
valueOf(java.lang.String name)
Returns the enum constant of this type with the specified name.static ThreadMode[]
values()
Returns an array containing the constants of this enum type, in the order they are declared.
-
-
-
Enum Constant Detail
-
POSTING
public static final ThreadMode POSTING
This is the default. Subscriber will be called directly in the same thread, which is posting the event. Event delivery implies the least overhead because it avoids thread switching completely. Thus, this is the recommended mode for simple tasks that are known to complete in a very short time without requiring the main thread. Event handlers using this mode must return quickly to avoid blocking the posting thread, which may be the main thread.
-
MAIN
public static final ThreadMode MAIN
On Android, subscriber will be called in Android's main thread (UI thread). If the posting thread is the main thread, subscriber methods will be called directly, blocking the posting thread. Otherwise the event is queued for delivery (non-blocking). Subscribers using this mode must return quickly to avoid blocking the main thread.If not on Android, behaves the same as
POSTING
.
-
MAIN_ORDERED
public static final ThreadMode MAIN_ORDERED
-
BACKGROUND
public static final ThreadMode BACKGROUND
On Android, subscriber will be called in a background thread. If posting thread is not the main thread, subscriber methods will be called directly in the posting thread. If the posting thread is the main thread, EventBus uses a single background thread, that will deliver all its events sequentially. Subscribers using this mode should try to return quickly to avoid blocking the background thread.If not on Android, always uses a background thread.
-
ASYNC
public static final ThreadMode ASYNC
Subscriber will be called in a separate thread. This is always independent of the posting thread and the main thread. Posting events never wait for subscriber methods using this mode. Subscriber methods should use this mode if their execution might take some time, e.g. for network access. Avoid triggering a large number of long-running asynchronous subscriber methods at the same time to limit the number of concurrent threads. EventBus uses a thread pool to efficiently reuse threads from completed asynchronous subscriber notifications.
-
-
Method Detail
-
values
public static ThreadMode[] values()
Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:for (ThreadMode c : ThreadMode.values()) System.out.println(c);
- Returns:
- an array containing the constants of this enum type, in the order they are declared
-
valueOf
public static ThreadMode valueOf(java.lang.String name)
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)- Parameters:
name
- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
java.lang.IllegalArgumentException
- if this enum type has no constant with the specified namejava.lang.NullPointerException
- if the argument is null
-
-