首页 > 试题广场 >

Servers can be designed to lim

[问答题]
Servers can be designed to limit the number of open connections.For example,a server may wish to have only N socket connections at any point in time.As soon as N connections are made,the server will not accept another incoming connection until an existing connection is released.Explain how semaphores can be used by a server to limit the number of concurrent connections.
推荐
A semaphore is initialized to the number of allowable open socket connections.When a connection is accepted,the acquire() method is called,when a connection is released,the release() method is called.If the system reaches the number of allowable socket connections,subsequent calls to acquire() will block until an existing connection is terminated and the release method is invoked.
发表于 2018-03-18 22:01:51 回复(0)