前言:
最近在开发的时候,在使用多线程的时候,发现了一些问题,不正确的使用,会产生oom的情况,后面看了阿里巴巴的开发手册,亲自验证了一下问题点
,解决了问题,特别mark一下
代码:
package com.ly.tcgl.sellservice.web.controller;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
import org.apache.tomcat.util.threads.ThreadPoolExecutor;
import java.util.concurrent.*;
/**
* @title: 多线程的使用方式,遵守阿里巴巴的规则,否则的话容易产生oom(outofmemory)
* @Author like.ma
* @Date: 2020-09-11 11:16
* @Version 1.0
*/
public class demo {
//错误的创建线程的方式
private static ExecutorService executorService= Executors.newFixedThreadPool(15);
//正确的创建线程的方式
private static ExecutorService executor = new ThreadPoolExecutor(10, 10,
60L, TimeUnit.SECONDS,
new ArrayBlockingQueue(10));
public static void main(String[] args){
for(int i=0;i
1648795721
查看更多评论