Package org.jruby.util.io
Class SelectorPool
java.lang.Object
org.jruby.util.io.SelectorPool
This is a simple implementation of a hard-referenced java.nio.channels.Selector
pool. It is intended to allow us to reuse a small pool of selectors rather
than creating them new for each use (which causes problem for Windows and
its socket-per-selector impl) or saving them per-thread (which causes
problems when there are many not-quite-dead threads in flight.
The selectors are kept open in the pool and you should call
cleanup()
for releasing selectors.- Author:
- headius
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
SelectorPool
public SelectorPool()
-
-
Method Details
-
get
Get a selector from the pool (or create a new one). Selectors come from the default selector provider on the current JVM.- Returns:
- a java.nio.channels.Selector
- Throws:
IOException
- if there's a problem opening a new selector
-
get
Get a selector from the pool (or create a new one). Selectors come from the given provider.- Returns:
- a java.nio.channels.Selector
- Throws:
IOException
- if there's a problem opening a new selector
-
put
Put a selector back into the pool.- Parameters:
selector
- the selector to put back
-
cleanup
public void cleanup()Clean up a pool. All selectors in a pool are closed and the pool gets empty.
-