I am writing a Java application that will create class objects to represent clients that are connected and registered with an external system on the other side of my application.
Each client object has two nested classes in it, which are interface and external. the interface class will continuously receive data from the actual client and send readings and data to the base class, which will receive this data from the external interface and send it to the external system using the appropriate format and protocol this system requires.
In design, we want every instance of the client object to be a stream. Then, in each stream, there will naturally be two [EDIT] sockets with their own NIO channels each [/ EDIT], one client, one system, located in the front and back, respectively. However, now this indicates the need for non-blocking sockets. I read a tutorial here that explains how to safely use a selector in the main thread to handle all streams with a connection.
But I need several selectors, each of which works in its own thread. From reading the aforementioned tutorial, I learned that key sets in a selector are not thread safe. Does this mean that individual Selectors created in their own repressive streams can create conflicting keys if I try to give them each of my pair of sockets and channels? Moving the selector to the main stream is a small opportunity, but far from ideal, based on the software requirements that have been given to me. Thank you for your help.
java multithreading css-selectors nio
michael.bartnett
source share