Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[jetty-users] Why does WebsocketClient work on multi threads as default?


If WebsockectClient class is initialized without a parameter, it launches about 8 threads (1 for internal scheduling, 7 threads for working). Why is it designed to work on multi threads as default? What is typical use case for multi threads?

In my projects, we found that we could not guarantee message order with default setting (multithread) because of a context switch. For example, even if WebsocketClient receive message A then B, message B  might be processed first in a @OnWebsocketMessage callback if a context switch happens.

We care message order in my project, so we usually specify an executor like below.

WebsocketClient client = new WebsocketClient(Executors.newFixedThreadPool(2));

(Note) We need at least two threads, one for internal scheduling and the another for actual working thread.

Yohei Onishi

Back to the top