当前位置:网站首页>Business local multithreading
Business local multithreading
2022-08-05 14:32:00 【fragrant tincture】
package com.vm.engine.audio.realtime;import java.util.Properties;import java.util.concurrent.ExecutorService;import java.util.concurrent.LinkedBlockingQueue;import java.util.concurrent.ThreadPoolExecutor;import java.util.concurrent.TimeUnit;import java.util.logging.Level;import java.util.logging.Logger;import org.jetbrains.annotations.NotNull;import org.jetbrains.annotations.Nullable;import org.json.JSONException;import org.json.JSONObject;public class WSListener extends WebSocketListener {private Logger logger = Logger.getGlobal();private static ExecutorService msgTaskService = null;static {//The business requires high stability, fixed threads, and unlimited to-do tasks are placed in the Queue (LinkedBlockingQueue), which will consume a certain amount of memorymsgTaskService=new ThreadPoolExecutor(8,8,30000L,TimeUnit.MILLISECONDS,new LinkedBlockingQueue());/*CPUNumber of physical CPUs (physical cpu): Refers to the number of physical CPUs actually inserted on the motherboard.cat /proc/cpuinfo | grep "physical id" | sort | uniq | wc -lNumber of cores (Core): Add cores to a single physical CPU, that is, dual-core or multi-core, so that a dual-core CPU can run two processes/threads at the same time.cat /proc/cpuinfo | grep "cpu cores" | uniqThe number of logical processors (Processor): a single core is logically divided into multiple in order to improve the processing power.cat /proc/cpuinfo | grep "processor" | wc -lJAVA get the number of cores available to the JVMRuntime.getRuntime().availableProcessors()How to set the number of core threads:CPU intensiveCPU-intensive tasks require a lot of computation and consume CPU resources. For example, video encoding and decoding are time-consuming operations. The more thread tasks, the more time spent in task switching. The number of threads should be reduced. CPU-intensiveThe number of task threads should be equal to the number of cores of the CPU.IO intensiveIO-intensive CPU consumption is relatively small, and most of the time is waiting for IO. The more threads, the higher the efficiency, but there are limitations. Our general applications belong to this category. The number of core threads = the number of CPU cores * 2.*/}public WSListener() {}public void business(String aa,String bb) {// must not block heremsgTaskService.execute(() -> {// handle businesslogger.info("Thread pool thread"+Thread.currentThread().getId());} catch (JSONException e) {logger.info(Thread.currentThread().getId()+" - Thread JSONException - [Error] "+e);throw new RuntimeException(e);}});}} 边栏推荐
- 当天期货开户次日就可以交易
- Product News | The digital platform trial environment is newly upgraded!Welcome to consult and try!
- PaddleOCR User Guide
- NLP paper reading | Parametric machine translation meets comparative learning: I want both efficiency and performance!
- 为什么你做自媒体赚不到钱?今天就教你几招
- JSCH 简单使用
- Feign 的简单使用
- 内存问题难定位,那是因为你没用ASAN
- The actual use of EOSJS in China Mobile Chain
- day7·拆包与装包
猜你喜欢
随机推荐
Some understanding of multithreading
神经网络的原理和应用,神经网络理论及应用
npm install时卡在sill idealTree buildDeps
恶访、黑产猖獗,做安全“守门人”| 创新场景50
PaddleOCR User Guide
Unity camera walkthrough script
抖音自媒体账号被限流?这3种方法教你如何鉴别
完成原型设计的五个步骤
字节跳动 Flink 状态查询实践与优化
什么是SNMP监控
开户的期货公司各有擅长的领域
CVE-2021-37580 Apache ShenYu 身份验证绕过漏洞复现
Thorns and Roses: The Road to Growth for Basic Service Architects PPT
‘proxy‘ config is set properly,see“npm help config“
图神经网络 图像处理,为什么用图神经网络
day5·全局与局部变量
day10· __init__方法
CF1714A 题解
十五个AI图像放大工具
Shell realizes automatic decompression of encrypted compressed files









