当前位置: 首页 > news >正文

门户网站管理系统阿里巴巴运营

门户网站管理系统,阿里巴巴运营,小程序制作方案书,用自己的身份做网站备案Handler 、 Thread 和 HandlerThread详解 区别: 1)Handler:在Android中负责发送和处理消息,通过它可以实现其他支线线程与主线程之间的消通讯 2)Thread:线程,可以看作是进程的一个实体&#xff…
Handler Thread HandlerThread详解
区别:
1)Handler:在Android中负责发送和处理消息,通过它可以实现其他支线线程与主线程之间的消通讯
2)Thread:线程,可以看作是进程的一个实体,是CPU调度和分派的基本单位,他是比进程更小的独立运行的基本单位
3)HandlerThread:封装了Handler + ThreadHandlerThread适合在有需要一个工作线程(非UI线程)+任务的等待队列的形式,优点是不会有堵塞,
减少了对性能的消耗,缺点是不能同时进行多个任务的处理,需要等待进行处理。处理效率低,可以当成一个轻量级的线程池来用
Handler 实现原理:
由 handler、Looper、MessageQueue 三部分组成,由handler  post( @NonNull Runnable r)消息到到MessageQueue( 单向链表),
而MessageQueue 由Looper 管理做无限的循环取消息队列里面的消息并将消息分给handler处理,
当消息一直循环到MessageQueue里没有消息了,循环就阻塞(相当于结束循环)
然后handler 通过回调方法回调消息给 handleMessage(Message msg) 处理;
部分源码截图:
1.handler 发送消息
2.looper  myLooper 获取一个Thread相对应唯一一个looper,和looper的构造函数(Thread. currentThread() 获取当前代码块被哪个线程调用)
  1. MessageQueue,一个入队方法enqueueMessage() 方法,一个出队方法
详细介绍MessageQueue 参考连接 https://www.sohu.com/a/145311556_675634

HandlerThread 实现  ,本质就是一个线程Thread,(其中封装Looper )

public class HandlerThread extends Thread {
    int mPriority;
    int mTid = -1;
    Looper mLooper;
    public HandlerThread(String name) {
        super(name);
        mPriority = Process.THREAD_PRIORITY_DEFAULT;
    }
    /**
     * Constructs a HandlerThread.
     * @param name
     * @param priority The priority to run the thread at. The value supplied must be from
     * {@link android.os.Process} and not from java.lang.Thread.
     */
    public HandlerThread(String name, int priority) {
        super(name);
        mPriority = priority;
    }
    /**
     * Call back method that can be explicitly overridden if needed to execute some
     * setup before Looper loops.
     */
    protected void onLooperPrepared() {
    }
    @Override
    public void run() {
        mTid = Process.myTid();
        Looper.prepare();
        synchronized (this) {
            mLooper = Looper.myLooper();
            notifyAll();
        }
        Process.setThreadPriority(mPriority);
        onLooperPrepared();
        Looper.loop();
        mTid = -1;
    }
    /**
     * This method returns the Looper associated with this thread. If this thread not been started
     * or for any reason is isAlive() returns false, this method will return null. If this thread
     * has been started, this method will block until the looper has been initialized.  
     * @return The looper.
     */
    public Looper getLooper() {
        if (!isAlive()) {
            return null;
        }
        // If the thread has been started, wait until the looper has been created.
        synchronized (this) {
            while (isAlive() && mLooper == null) {
                try {
                    wait();
                } catch (InterruptedException e) {
                }
            }
        }
        return mLooper;
    }
    public boolean quit() {
        Looper looper = getLooper();
        if (looper != null) {
            looper.quit();
            return true;
        }
        return false;
    }
    public boolean quitSafely() {
        Looper looper = getLooper();
        if (looper != null) {
            looper.quitSafely();
            return true;
        }
        return false;
    }
    /**
     * Returns the identifier of this thread. See Process.myTid().
     */
    public int getThreadId() {
        return mTid;
    }
}
http://www.yidumall.com/news/100613.html

相关文章:

  • 网站制作新报价百度识图网页入口
  • wordpress参考文档优化大师的优化项目有哪7个
  • 龙华专业做网站公司企业推广宣传文案
  • 做网站什么数据库用的多北京百度快照推广公司
  • 网站做的最好的网站有哪些seo友情链接
  • wordpress自带搜索吗北京网优化seo优化公司
  • 餐饮网站建设怎样长沙seo优化哪家好
  • 在公司网站投简历该怎么做产品怎么进行推广
  • 网站策划专员所需知识seo专业培训机构
  • 辽宁疫情最新消息今天百度seo建议
  • 做母婴的网站校园推广
  • 给网站怎么做tag标签网页制作网站
  • 静态网站建设cps推广接单平台
  • 免费做优化的网站网络营销的原理
  • 263企业会议邮箱登录入口seo平台代理
  • 网络培训软件系统优化app
  • 运城市做网站百度热搜词排行榜
  • html5响应式公司网站模版百度seo排名原理
  • 怎么再贴吧给自己的网站做宣传百度seo搜索引擎优化培训
  • dns加网站腾讯朋友圈广告代理
  • 山东做网站建设公司推广普通话奋进新征程手抄报
  • 大连做企业网站排名百度seo按天计费
  • 局强化网站建设和管理seo外包公司优化
  • 做医学期刊杂志网站上海关键词排名优化价格
  • 连云港做网站哪家好产品软文范例800字
  • 做计算机网站有哪些功能推广软文范文800字
  • 深圳做电商平台网站建设成都专门做网站的公司
  • 简单手机网站开发软件发帖推广百度首页
  • 网站开发常见问题百度网址提交
  • 软件ui设计怎么做网站网站优化排名工具