Suraj Chandran
Suraj Chandran

Reputation: 24801

Why custom NIO Selector Provider?

Does anyone know why would we ever need a custom selector provider in java NIO. Is there anyone who has ever used a custom selector provider and why would you do that?

Upvotes: 2

Views: 1375

Answers (3)

martin-g
martin-g

Reputation: 17533

At the time of writing JDK 16 (Early Access) provides SelectorProviders for epoll and poll. Linux kernel 5.1+ provides io_uring which is claimed to be more performant and more flexible than epoll.

Being able to use a custom SelectorProvider via system property or via ServiceLoader makes it possible to use io_uring even with old JVMs.

I wasn't able to find any open source implementation so far!

Upvotes: 0

Jerome
Jerome

Reputation: 2370

Mock implementation.

It can be quite useful to write unit tests against code which uses NIO. Otherwise, it could be tricky to simulate various kinds of network failure.

Upvotes: 2

user207421
user207421

Reputation: 311022

I wrote one to provide SSLSocketChannels and SSLServerSocketChannels (and SSLSelectors ...). I can also imagine writing one to provide proxying, as java.net.Proxy and the like aren't supported at all in java.nio.

Upvotes: 4

Related Questions