Skip to content

Synchronous and Asynchronous I/O

Synchronous and Asynchronous I/O are two distinct strategies for handling data transmission between a program and the operating system (OS). These concepts describe the communication mechanism used for result messages and define how the calling party waits for input/output operations to complete.^[600-developer__java__java-io__bio-nio-aio.md]

Synchronous I/O

In a synchronous I/O model, the caller must actively participate in the I/O process.^[600-developer__java__java-io__bio-nio-aio.md]

  • Mechanism: The synchronous approach focuses on active waiting. The calling party initiates the operation and waits for it to finish before proceeding.^[600-developer__java__java-io__bio-nio-aio.md]
  • Behavior: The OS typically blocks the I/O stream once data processing is complete. Alternatively, if non-blocking behavior is implemented within the synchronous model, the system may continuously poll (asking "is it done yet?") to check for completion.^[600-developer__java__java-io__bio-nio-aio.md]

Asynchronous I/O

In an Asynchronous I/O model, the operating system handles the I/O operation independently.^[600-developer__java__java-io__bio-nio-aio.md]

  • Mechanism: The calling party does not need to wait for the result to be returned immediately.^[600-developer__java__java-io__bio-nio-aio.md]
  • Notification: Instead of active waiting, the system relies on other mechanisms such as state notifications or callback functions to signal that the operation has finished.^[600-developer__java__java-io__bio-nio-aio.md]
  • Efficiency: This model allows the program to perform other tasks while the OS manages the I/O via polling or event listening.^[600-developer__java__java-io__bio-nio-aio.md]

Comparison with Blocking vs. Non-blocking

While often discussed together, Synchronous/Asynchronous and Blocking/Non-blocking describe different aspects of system behavior:

  • Blocking vs. Non-blocking: Describes the state of the thread when data is not ready. Blocking implies the thread is suspended waiting, while Non-blocking implies the thread receives an immediate return and can try again later.^[600-developer__java__java-io__bio-nio-aio.md]
  • Combinations: These concepts can be combined into four distinct modes:
    • Synchronous Blocking
    • Synchronous Non-blocking
    • Asynchronous Blocking (often considered impractical or marked as "X")
    • Asynchronous Non-blocking^[600-developer__java__java-io__bio-nio-aio.md]

Sources

  • 600-developer__java__java-io__bio-nio-aio.md