Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Multithreading 在tomcat中使用多个线程处理websocket输入消息_Multithreading_Tomcat_Concurrency_Websocket_Throughput - Fatal编程技术网

Multithreading 在tomcat中使用多个线程处理websocket输入消息

Multithreading 在tomcat中使用多个线程处理websocket输入消息,multithreading,tomcat,concurrency,websocket,throughput,Multithreading,Tomcat,Concurrency,Websocket,Throughput,据我所知(如果我错了,请纠正我),在tomcat中,传入的websocket消息是按顺序处理的。这意味着,如果您在一个websocket中有100条传入消息,那么将仅使用一个线程从消息1到消息100逐个处理它们 但这对我不起作用。我需要同时处理websocket中的传入消息,以提高websocket吞吐量。传入的消息互不依赖,因此不需要按顺序处理 问题是如何配置tomcat,使其能够为每个websocket分配多个工作线程来并发处理传入消息 任何暗示都将不胜感激 这就是我认为每个websock

据我所知(如果我错了,请纠正我),在tomcat中,传入的websocket消息是按顺序处理的。这意味着,如果您在一个websocket中有100条传入消息,那么将仅使用一个线程从消息1到消息100逐个处理它们

但这对我不起作用。我需要同时处理websocket中的传入消息,以提高websocket吞吐量。传入的消息互不依赖,因此不需要按顺序处理

问题是如何配置tomcat,使其能够为每个websocket分配多个工作线程来并发处理传入消息

任何暗示都将不胜感激


这就是我认为每个websocket连接都会阻塞的地方(这是有意义的):


您不能配置Tomcat来执行您想要的操作。您需要编写一个消息处理程序来使用该消息,将其传递给执行器(或类似的执行器进行处理),然后返回

/**
 * Called when there is data in the ServletInputStream to process.
 *
 * @throws IOException if an I/O error occurs while processing the available
 *                     data
 */
public void onDataAvailable() throws IOException {
    synchronized (connectionReadLock) {
        while (isOpen() && sis.isReady()) {
            // Fill up the input buffer with as much data as we can
            int read = sis.read(
                    inputBuffer, writePos, inputBuffer.length - writePos);
            if (read == 0) {
                return;
            }
            if (read == -1) {
                throw new EOFException();
            }
            writePos += read;
            processInputBuffer();
        }
    }
}