I am developing a peer to peer application.
in that each peer has one server socket channel and a socket channel,..
Now i need two selectors to handle the connection for server socket channel and socket channel,…
SelectorProvider seems to be a singleton class and it fices only a single instance of Selector,.. which i cant able to use for both the socket channel,..
is there a way to use two selectors in a single instance of a program,..
private ServerSocketChannel svrScktChnl;
private SocketChannel socketChannel;
two selector
public Selector selector=null;
public Selector playerSelector=null;
i am try to intialize these selector separately one for server socket channel and another for socket channel,..
But i cant initialize once again because it throws an error,,..
No you don’t. You can use the same Selector for both, unless for some reason not stated here you want to handle them in separate threads, which is really a violation of everything that NIO stands for.
False.
SelectorProvider.provider()returns a singleton, but you don’t need to use it: there are APIs everywhere that let you specify your own provider. Not that it’s relevant, because:False. I don’t know what you mean by ‘fices’, but
SelectorProvider.openSelector()returns a newSelectorevery time you call it, which you could have discovered for yourself without the luxurious technique of posting a question here and waiting possibly forever for a possibly incorrect answer, even if the Provider itself was a singleton, which it isn’t.No. Clearly you’ve never actually tried it. You need to understand that this is an empirical science where you are expected to conduct your own experiments. Posting questions on Internet sites and sitting back waiting for the answers is not an efficient use of your time or anybody else’s, and it is not calculated to deliver the correct answer as quickly as doing your own work.
You can’t seriously expect anyone to help you with as little information as that. Would you accept that as a bug report from a customer?