Java FAQ _01 Basic Concepts (015) _ Blocking, non-blocking what is the difference

Source: Internet
Author: User

Click to enter _ more _java thousand ask

1. What is the difference between blocking and non-blocking?

In network programming, we often see synchronous, asynchronous, blocking, non-blocking, four calls and their combinations.
Understanding synchronous, asynchronous look here: What is the difference between synchronous and asynchronous
The blocking mode, non-blocking mode is mainly for the service side (server), specifically as follows:

Block (block)

A blocking call means that the current thread is suspended until the call results are returned. Suspend that thread into a non-executable state, in which the CPU does not allocate a time slice to the thread, that is, the thread pauses to run.

See the status of threads here: What are the status of threads
A blocking call causes the thread to wait all the time, and when the call is not completed there is another request, which opens a new thread to execute and consumes more thread resources.

Because most of the time the blocking thread is wasted waiting on the request, it cannot handle too many requests.

Non-blocking (Unblock)

Non-blocking is relative blocking, which means that the call does not block the current thread and returns immediately.

Non-blocking is the question of whether the data is ready to be queried by polling, and if it is ready to get the data proactively. During this time the thread is not suspended.

The number of threads for a non-blocking processing connection is not linked to the number of requests, which means that many requests can be processed by relatively few threads.

In summary, the difference between blocking and non-blocking: When a request is issued, no data arrives and returns immediately.

Java FAQ _01 Basic Concepts (015) _ Blocking, non-blocking what is the difference

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.