Hello I would like to know the best way to broadcast a message for many clients. Should I use a executor from a thread pool and dispatch the message to each context.getResponse in a different thread like this:
for (final AsyncContext ctx : clients) { executors.execute(new Runnable() { public void run() { try { PrintWriter writer = ctx.getResponse().getWriter(); writer .println(message); writer.flush(); } catch (IOException e) { e.printStackTrace(); } } }); } Or the best way would be to send the message to each ctx.getResponse() inside the same thread (putting the foreach inside the Runnable)? The question is: is ctx.getResponse().print really fast that it only puts the String inside the buffer that will be dispatched later (in an async fashion) to the client? Even more, is ctx.getResponse().getWriter().print() a thread safe call? If there are two broadcasts, what happens if we have a concurrent call to the writer.print()? can the buffer loose data or both calls will succeed without guaranting the order. thanks -- Paulo Silveira Caelum | Ensino e Inovação www.caelum.com.br www.arquiteturajava.com.br --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org