【问题标题】:Android Looper vs BlockingQueue?Android Looper vs BlockingQueue?
【发布时间】:2013-02-16 02:02:52
【问题描述】:

谁能解释为什么有人应该使用 Android Looper 功能来创建“管道线程”而不是创建一个从 BlockingQueue 中提取任务的普通线程?从表面上看,这似乎是做同一件事的两种方式。

【问题讨论】:

    标签: android blockingqueue looper


    【解决方案1】:

    BlockingQueue 允许您拥有多个消费者和生产者,而 Looper 机制允许您拥有多个生产者但只有一个消费者。

    因此,在 Looper 线程中,您一次只能执行一个任务(可运行)。 Looper 机制的创建使您可以轻松地在 UI 线程(作为单线程运行,因此将其视为单线程使用者)上执行可运行对象(封装为消息的任务)

    Looper/Handler 还提供延迟执行任务的功能,而 BlockingQueue 开箱即用。这在 UI 工具包的上下文中也很重要。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-05-28
      • 2011-02-17
      • 2011-10-10
      • 2023-03-30
      • 2013-09-29
      • 2011-10-22
      • 2011-07-16
      相关资源
      最近更新 更多