
线程池
平静不绝望
ALOHA HEJA HE
-
原创 【IO】Java异步非阻塞编程的几种方式
1 服务端执行,最简单的同步调用方式:缺陷: 服务端响应之前,IO会阻塞在: java.net.SocketInputStream#socketRead0 的native方法上:2 JDK NIO & Future java 1.5之后优点:主线程可以不用等待IO响应,可以去做点其他的,比如说再发送一个IO请求,可以等到一起返回; 缺点: 主线程在等待结果返回过程中依然需要等待,没有根本解决此问题;3 使用Callback回调方式优点:主线程完成发送请求后,再也不用关心这.2021-02-25 20:12:3314
0
-
原创 【线程池】java 1.8 ThreadPoolExecutor 类源码解读
1 线程池:why?主要解决1 异步任务 2 生产者消费者场景2 参数详解2.1 核心线程数// 小于核心线程数:任务提交时创建新的线程,即使其他线程空闲;When a new task is submitted in method {@link #execute(Runnable)}, and fewer than corePoolSize threads are running, a new thread is created to handle the request, eve..2021-01-30 16:52:5959
2
-
原创 【Daemon】守护和非守护线程鲜为人知的事实
1 总结(英文+翻译)如下:Non-daemon threads are also known as ‘user’ threads // 非守护程序线程也称为“用户”线程。JVM will not exit even if only 1 non-daemon (i.e. user) thread is alive. On the other hand, JVM will exit even if multiple daemon threads are alive. // 即使只有1个非守护程序(即用户2020-12-11 10:01:5079
1
-
原创 【面试】--三个线程轮流打印ABC
1 lock实现public class ABCLock { private static Lock lock = new ReentrantLock(); private static Condition conditionA = lock.newCondition(); private static Condition conditionB = lock.ne2020-08-16 15:13:5362
0
-
原创 【线程池】线程池的线程遇到异常后去哪里?怎么处理?
1 四种解决任务代码抛异常的方案:在我们提供的Runnable的run方法中捕获任务代码可能抛出的所有异常,包括未检测异常 使用ExecutorService.submit执行任务,利用返回的Future对象的get方法接收抛出的异常,然后进行处理 重写ThreadPoolExecutor.afterExecute方法,处理传递到afterExecute方法中的异常 为工作者线程设置Un...2020-03-29 16:33:58437
0
-
原创 【技能库】--批量任务多线程并发执行(324)
扩展callable 接口 并且 Futrue import com.alibaba.fastjson.JSON;import com.google.common.collect.Lists;import com.google.common.util.concurrent.Uninterruptibles;import org.apache.commons.la2017-09-16 14:13:041387
0
-
原创 【快速工具】top cpu load最忙的前五线程 tool
top 线程分析:在机器上执行如下三个步骤即可找到最繁忙的线程信息:1 wget https://raw.githubusercontent.com/iqiancheng/fast-profiler/master/show-busy-java-threads.sh2 sudo chmod u+x show-busy-java-threads.sh3 sudo ./show-busy...2019-04-26 23:15:14114
0
-
原创 优雅关机 -- springboot 优雅关机tomcat 线程池
import org.apache.catalina.connector.Connector;import org.slf4j.Logger;import org.slf4j.LoggerFactory;import org.springframework.boot.web.embedded.tomcat.TomcatConnectorCustomizer;import org.spri...2019-04-29 00:03:32616
0
-
原创 redis pipeline 事务到底怎么回事呢? 怎么执行的?
MULTI,EXEC,DISCARDandWATCHare the foundation of transactions in Redis.They allow the execution of a group of commands in a single step, with two important guarantees: All the commands in a tr...2019-04-25 11:47:27559
0