1. You canmanage multiple SelectableChannel through Selector. Its select() method can monitor which channels are ready for I/O operations. The return value represents the number of these I/Os.
int select() int select(long timeout) int selectNow()
2, When the select() method is called, it will save the SelectionKey representing the channel that is ready for I/O operations in a collection, which can be returned through selectedKeys() .
Set<SelectionKey> selectedKeys()
select()'s three methods, you can see the differences between these methods from the naming. The first method is a blocking call, the third method sets a timeout, and the third method Three methods return immediately.
1. Simple. As long as you understand the basic concepts, you can write applications suitable for various situations;
2. Object-oriented ;
3. Distribution, Java is a network-oriented language;
4. Robustness, Java provides automatic garbage collection for memory management, preventing programmers from easily generating errors when managing memory. Error;
5. Security, Java used in network and distributed environments must prevent virus intrusion;
6. Architecture neutrality, as long as the Java runtime system is installed, Can run on any processor;
7. Portability, Java can be easily transplanted to different machines on the network;
8. Interpretation and execution, the Java interpreter directly interprets Java words Section code is interpreted and executed.
The above is the detailed content of How to select the channel in java's Selector. For more information, please follow other related articles on the PHP Chinese website!