zoukankan      html  css  js  c++  java
  • Parallel vs Synchronous vs Asynchronous

    [1] https://www.sohamkamani.com/blog/2016/03/14/wrapping-your-head-around-async-programming/

    [2] https://codewala.net/2015/07/29/concurrency-vs-multi-threading-vs-asynchronous-programming-explained/

    Parallel

    Parallelism means that two or more calculations happen simultaneously.

    Concurrency

    Concurrency means that two or more calculations happen within the same time frame, and there is usually some sort of dependency between them

    Synchronous Programming Model

    1. Single Threaded

    A thread is assigned to one task and starts working on it. Once the task completes then it is available for the next task. In this model, it cannot leave the executing task in mid to take up another task.

    So a thread could only execute task1 and then task2 and so on.

    2. Multi-threaded

    A typical thread pool/execurot service has a bunch of threads and each thread will pick up one task and finish it, before taking another task.

    Asynchronous Programming Model

    1. Single Threaded

    A thread once start executing a task, it can hold it in middle, save the current state and start executing another task.

    So a thread could execute task1, then task2 and then task1 again.

    2. Multi-threaded

    Multiple threads could be used to work on a bunch of tasks all together. so thread 1 could execute task1, save the state and then work on task2. In the meantime, thread 2 could work on task3, save the state and then work on task1, which was worked by thread 1.

    Every thread could work on one task, save the state and pickup the task that left by another thread.

    Synchronous vs Asynchronous 

    The whole point of asynchronous programming is to free up threads. This is especially important when we have many IO related tasks (network reading or writing, disk reading or writing). 

    For a web application, even if we just have one thread serving all incoming REST request, aysnchronous programming model will let the thread delegate the waiting time to other threads and return immediately to serve other requests. Non-stopping is the whole idea of asynchronous programming.

  • 相关阅读:
    将打开的网页以html格式下载到本地
    Shiro自定义realm实现密码验证及登录、密码加密注册、修改密码的验证
    JS或jsp获取Session中保存的值
    HTML添加上传图片并进行预览
    springMVC多图片压缩上传的实现
    DropZone图片上传控件的使用
    Wireshark安装使用及报文分析
    Spring—Document root element "beans", must match DOCTYPE root "null"分析及解决方法
    web.xml中如何设置配置文件的加载路径
    正则表达式的认识
  • 原文地址:https://www.cnblogs.com/codingforum/p/9083828.html
Copyright © 2011-2022 走看看