Home  >  Q&A  >  body text

在html5中,多线程worker和异步ajax有什么区别?

在html5中,多线程worker和异步ajax有什么区别?

高洛峰高洛峰2717 days ago398

reply all(2)I'll reply

  • PHP中文网

    PHP中文网2017-04-17 13:31:51

    Multi-threading belongs to the category of concurrency, while asynchronous is the category of data request methods, as opposed to synchronization.

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-04-17 13:31:51

    I agree with the explanation above. The difference between them is huge. In terms of specific usage scenarios, CPU-consuming tasks can be moved to workers for processing. Ajax is mainly time-consuming for IO. In order to ensure that the code is not blocked, it is processed asynchronously and notified when the data arrives. program. This is a workaround in HTML5, because ajax was implemented relatively early, and worker is a relatively new concept. It can be said that the function of worker covers ajax, but such problems naturally arise due to the continuous development of HTML.
    In other languages, time-consuming tasks are generally placed in other threads to avoid blocking the main thread. Regardless of whether it costs CPU or IO.
    In short, it’s all HTML’s fault. You can also handle network requests in workers, but unfortunately, there are not many browsers that support workers.

    reply
    0
  • Cancelreply