码迷,mamicode.com
首页 > 其他好文 > 详细

同步异步

时间:2014-09-07 20:58:05      阅读:268      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   os   io   java   ar   strong   

知道什么叫同步和异步吗?

In synchronous receiving, while the server is waiting to receive data from a client, if the stream is empty the main thread will block until the request for data is satisfied. Hence, the server cannot do anything else until it receives data from the client. If another client attempts to connect to the server at that time, the server cannot process that request because it is blocked on the first client. This behavior is not acceptable for a real-world application where we need to support multiple clients at the same time. In asynchronous communication, while the server is listening or receiving data from a client, it can still process connection requests from other clients as well as receive data from those clients. When a server is receiving asynchronously, a separate thread (at the OS level) listens on the socket and will invoke a callback function (specified when the asynchronous listening was commenced) when a socket event occurs. This callback function in turn will respond and process that socket event. For example, if the remote program writes some data to the socket, a "read data event" (callback function you specify) is invoked; it knows how to read the data from the socket at that point.

 

转自:http://blog.csdn.net/xiaocaichonga/article/details/7723960

同步异步

标签:style   blog   http   color   os   io   java   ar   strong   

原文地址:http://www.cnblogs.com/cdwodm/p/3960709.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!