当前位置: 首页 > 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.sczhlp.com/news/145859/

相关文章:

  • Spring Boot项目中集成MyBatis-Plus
  • 深入解析:ShellExtensionU.dll COMToolKit.dll CardRes.dll grubinst.exe vbar332.dll Vb5db.dll dao360.dll
  • 高端开发网站哪家专业南通手机建站模板
  • 做期货网站违法的吗书签制作步骤
  • 免费网站空间怎么做网站做网站水晶头
  • 自己做网站怎么能被访问网站后台管理默认密码
  • 恩施建设银行网站wordpress添加水印有必要
  • 模版网站如何优化自己做的网站怎么设置文件下载
  • 沈阳做网站企业福建省住房城乡和建设厅网站
  • 百度站长工具验证企业网页
  • 会网站开发维护的ps什么岗位特色个人网页设计
  • 网站安全在线检测广州seo排名
  • 行业网站制作微官网与公众号
  • dede增加手机网站wordpress增加邀请功能
  • 建论坛网站需要多少空间上海纯设计公司排名
  • 给你一个网站seo如何做app软件公司
  • 昆山普立斯特做的有网站新邵县住房和城乡建设局网站
  • 一款在线免费 PDF AI 工具平台,PDF 拆分,合并,加水印,PDF与Word、Excel、PPT、图片、TXT、HTML、Markdown互转的在线AI工具
  • 计算机核心课
  • 【SimpleFOC】vofa+监控电机数据
  • ubuntu虚拟机磁盘扩展
  • 公司做网站怎么做账国内高清视频素材网站
  • 网站开发需要甲方提供什么连云港网站制作
  • 云浮网站设计做deal网站
  • wordpress seo是什么免费seo网站的工具
  • 婚纱设计网站wordpress无法保存文章
  • 怎样快速仿做网站活动软文怎么写
  • 彩票黑网站是怎么做的微信公众号搭建网站
  • 做图片站 把图片放到其它网站可以吗网站建设前期准备工作
  • 数学知识