• 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.

  • 相关阅读:
    软工作业06
    软工作业05
    软工作业00
    软工作业04
    软工作业03
    软工作业02
    我的随笔
    2020软件工程个人作业06——软件工程实践总结作业
    2020软件工程作业05
    软件工程作业00——问题清单
  • 原文地址:https://www.cnblogs.com/codingforum/p/9083828.html
Copyright © 2020-2023  润新知