Java. Io .*
It is the most primitive and simplest Io operation.
It is usually easy to use and suitable for scenarios with a small number of concurrent jobs.
Io is blocked.
For multiple sockets, you may need to create one per socket.
Thread for processing. Think about 1000 or more cases.
What will the server look like? The server is busy with thread switching.
Java. NiO .*
This is a Java asynchronous Io Processing Package. socket is generally used
The select mechanism is that the CPU constantly queries All socket
Handle. If there is an event, it will report. It is much better than Java. Io. *.
However, it is not very convenient to use, but there are many open-source
NIO framework can be used. apahce Mina/windy, etc.
Methods are similar. encapsulation is good.
However, the CPU usage is obviously high in this case.
Iocp (Windows), kqueue (FreeBSD), or epoll (Linux)
High-performance socket.
Generally, online games use these technologies for network connection architecture.
I heard that QQ game uses epoll, which is supported by a single server.
Tens of thousands of socket connections.
Fortunately, jdk6.0 began to support epoll.
A new java. NiO. channels. selectorprovider implementation that is based
On the Linux epoll Event Notification facility is supported ded.
The epoll facility is available in the Linux 2.6, and newer,
Kernels. The new epoll-based selectorprovider implementation
Is more scalable than the traditional poll-based selectorprovider
Implementation when there are thousands of selectablechannels
Registered with a selector. The new selectorprovider implementation
Will be used by default when the 2.6 kernel is detected.
The poll-based selectorprovider will be used when a pre-2.6 kernel is detected.
On the Internet, we can see that epoll has been implemented in jdk5.0.
The epoll selectorprovider will be supported ded in 5.0 Update 9.
To enable it requires setting the system property
Java. NiO. channels. SPI. selectorprovider to the value
Sun. NiO. Ch. epollselectorprovider
Summary:
Java. Io .*
It is equivalent that 1000 militia members go to the village to wait for the devil to kill one.
Personal comment: you cannot open a station in the village!
Select
It is equivalent to repeatedly asking "Have you ever entered the village ?", "Have you entered the village ?"...
Personal comments: I'm bored. I'm not doing anything right.
Iocp (Windows), kqueue (FreeBSD), or epoll (Linux)
A person goes to the village gate to stand for a post and waits for the devil to come and report.