MessageQueue 相关概念

本文介绍了ThreadLocal类实现的线程局部存储概念,每个线程可以拥有独立的变量副本。此外还探讨了Looper类如何为线程运行消息循环,Message类用于发送消息到Handler,以及MessageQueue作为消息调度的基础组件。

/**
 * Implements a thread-local storage, that is, a variable for which each thread
 * has its own value. All threads share the same {
@code ThreadLocal} object,
 * but each sees a different value when accessing it, and changes made by one
 * thread do not affect the other threads. The implementation supports
 * {
@code null} values.
 *
 *
@see java.lang.Thread
 *
@author Bob Lee
 */
public class ThreadLocal<T>

 

 

/**
  * Class used to run a message loop for a thread.  Threads by default do
  * not have a message loop associated with them; to create one, call
  * {
@link #prepare} in the thread that is to run the loop, and then
  * {
@link #loop} to have it process messages until the loop is stopped.

 

public final class Looper 

 

/**
 *
 * Defines a message containing a description and arbitrary data object that can be
 * sent to a {
@link Handler}.  This object contains two extra int fields and an
 * extra object field that allow you to not do allocations in many cases. 
 *
 *
While the constructor of Message is public, the best way to get
 * one of these is to call {
@link #obtain Message.obtain()} or one of the
 * {
@link Handler#obtainMessage Handler.obtainMessage()} methods, which will pull
 * them from a pool of recycled objects.
</p>
 */
public final class Message implements Parcelable

 

/**
 * Low-level class holding the list of messages to be dispatched by a
 * {
@link Looper}.  Messages are not added directly to a MessageQueue,
 * but rather through {
@link Handler} objects associated with the Looper.
 *
 *
<p>You can retrieve the MessageQueue for the current thread with
 * {
@link Looper#myQueue() Looper.myQueue()}.
 */
public final class MessageQueue

 

/**
 * A Handler allows you to send and process {
@link Message} and Runnable
 * objects associated with a thread's {
@link MessageQueue}.  Each Handler
 * instance is associated with a single thread and that thread's message
 * queue.  When you create a new Handler, it is bound to the thread /
 * message queue of the thread that is creating it -- from that point on,
 * it will deliver messages and runnables to that message queue and execute
 * them as they come out of the message queue.

 

public class Handler

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值