在使用executors并发编程时候需要注意,如果出现Thread table can't grow past 16383 threads异常,详情如下:
[WARN ] Thread table can't grow past 16383 threads. [ERROR][thread ] Could not start thread pool-7975-thread-1. errorcode -1 Exception in thread "Thread-1445" java.lang.Error: errorcode -1 at java.lang.Thread.start0(Native Method) at java.lang.Thread.start(Thread.java:597) at java.util.concurrent.ThreadPoolExecutor.addIfUnderCorePoolSize(ThreadPoolExecutor.java:703) at java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:652) at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:92)
需要注意在finally中需要调用shutdown()方法。
测试程序如下:
import java.util.concurrent.*; public class Test{ public static void main(String[] args){ while (true){ ExecutorService es = null; try { es = Executors.newCachedThreadPool(); for (int i = 0; i < 2; i++) { es.submit(new Car()); } } catch (RuntimeException e) { e.printStackTrace(); continue; } finally { es.shutdown(); } } } public static class Car implements Runnable { public void run() { System.out.println("Car <" + Thread.currentThread().getName() + "> doing something"); } } }
若 注释掉es.shutdown()这一行,会出现 “[WARN ] Thread table can't grow past 16383 threads.
[ERROR][thread ] Could not start thread pool-8062-thread-1. errorcode -1
Exception in thread "Main Thread" java.lang.Error: errorcode -1” 错误。
具体原因待查。。
相关推荐
线程池 Executors
This concise book empowers all Java developers to master the complexity of the Java thread APIs and concurrency utilities. This knowledge aids the Java developer in writing correct and complex ...
java Executors 使用实例 concurrent.ExecutorService
Java中Executors类中几种创建各类型线程池方法及简单实例
Executors: 是java.util.concurrent包下的一个类,提供了若干个静态方法,用于生成不同类型的线程池。Executors一共可以创建下面这四类线程池: 1.newFixedThreadPool创建一个可缓存线程池,如果线程池长度超过...
顶层接口Executors详解
This concise book empowers all Java developers to master the complexity of the Java thread APIs and concurrency utilities. This knowledge aids the Java developer in writing correct and complex ...
java线程池Executors实现数据批量操作。 批量异步Executors处理数据,实现限流操作,QPS限流。 线程池调用第三方接口限流实现逻辑。 案例适合: 1.批量处理大数据。 2.数据批量导出。 3任务数据异步执行。 4.多线程...
NULL 博文链接:https://bijian1013.iteye.com/blog/2284676
C++ library for executors
5_Executors源码阅读1
Chapter 4, Thread Executors will teach the readers to delegate the thread management to executors. They allow running, managing, and getting the results of concurrent tasks. Chapter 5, Fork/Join ...
Executors类的基本用法 2.1 创建线程池 2.2 提交任务 2.3 关闭线程池 线程池的分类 3.1 FixedThreadPool 3.2 CachedThreadPool 3.3 ScheduledThreadPool 3.4 SingleThreadExecutor 3.5 WorkStealingPool 线程池的...
java 线程池管理类:Executors_.docx
主要介绍了Java并发编程中使用Executors类创建和管理线程的用法,文中举了用其启动线程和设置线程优先级的例子,需要的朋友可以参考下
【强制】线程池不允许使用Executors去创建,而是通过ThreadPoolExecutor的方式,这样的处理方式让写的同学更加明确线程池的运行规则,规避资源耗尽的风险。 说明:Executors返回的线程池对象的弊端如下: 1) ...
《阿里巴巴Java开发手册》是阿里内部Java工程师所遵循的开发规范,涵盖编程规约、单元测试规约、异常日志规约、MySQL规约、工程规约、安全规约等,这是近万名阿里Java技术精英的经验总结,并经历了多次大规模一线...
Java并发编程中使用Executors类创建和管理线程的用法共4页.pdf.zip
主要介绍了java 中Executor, ExecutorService 和 Executors 间的不同的相关资料,需要的朋友可以参考下
资源分类:Python库 所属语言:Python 资源全名:more-executors-1.19.1.tar.gz 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059