Is it safe to pass the same ExecutorService instance to multiple NioServerSocketChannelFactory in Netty

StackOverflow https://stackoverflow.com/questions/9394197

  •  29-10-2019
  •  | 
  •  

Question

I have a tcp server running at port xxxx and flash policy server(again tcp) at port 843. Is it ok if I pass the same ExecutorService instance while creating the server bootstrap's for both servers? Will it lead to data corruption?

ExecutorService boss = Executors.newCachedThreadPool(new NamedThreadFactory("TCP-Server-Boss")
ExecutorService worker = Executors.newCachedThreadPool(new NamedThreadFactory("TCP-Server-Worker")
serverBootstrap = new ServerBootstrap(new NioServerSocketChannelFactory(boss,worker))

Now I want to pass the same boss and worker to the flash policy servers serverBootstrap. Is this a valid usage?

Was it helpful?

Solution

The ExecutorService returned by newCachedThreadPool() is not guaranteed to be threadsafe anywhere in the documentation. So it would be the correct action to create two new ExecutorServices.

Im quite sure the instances returned are threadsafe regardless of the documentation, but I would still make two new ExecutorServices with different names to ease debugging and readability.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top