IDEA load project 慢问题排查

去打开 IDEA 的 DEBUG 日志,日志地址在 help - Show log in finder 里,日志配置文件在 /Applications/IntelliJ IDEA.app/Contents/bin/log.xml。启动时的日志有一段明显很值得怀疑:

1
2
2018-05-06 15:34:45,576 [  93768]   INFO - ij.components.ComponentManager - com.seventh7.mybatis.ref.CmProject initialized in 75086 ms
2018-05-06 15:34:45,588 [ 93780] INFO - ellij.project.impl.ProjectImpl - 152 project components initialized in 75849 ms

com.seventh7.mybatis.ref.CmProject 初始化耗了 75 秒。去把 MyBatis 插件禁用以后重新测试:

1
2018-05-06 15:40:13,639 [ 138286]   INFO - ellij.project.impl.ProjectImpl - 150 project components initialized in 999 ms

Read More ...

AtomicInteger的lazySet探究

研究 ForkJoinPool 的时候碰到如下代码:

1
2
3
4
5
6
7
8
9
10
final boolean tryUnpush(ForkJoinTask<?> t) {
ForkJoinTask<?>[] a; int s;
if ((a = array) != null && (s = top) != base &&
U.compareAndSwapObject
(a, (((a.length - 1) & --s) << ASHIFT) + ABASE, t, null)) {
U.putOrderedInt(this, QTOP, s);
return true;
}
return false;
}

U.putOrderedInt 这个方法有点迷惑,他和 AtomicInteger 的 lazySet 是一个机制。然后查了些资料:

Read More ...

jdk8 fork/join 框架探究

直接看代码

join

1
2
3
4
5
6
7
public final V join() {
int s;
if ((s = doJoin() & DONE_MASK) != NORMAL)
// 如果没有正常完成去处理异常
reportException(s);
return getRawResult();
}

doJoin

1
2
3
4
5
6
7
8
9
10
private int doJoin() {
int s; Thread t; ForkJoinWorkerThread wt; ForkJoinPool.WorkQueue w;
// status<0表示任务已经执行完毕
return (s = status) < 0 ? s :
((t = Thread.currentThread()) instanceof ForkJoinWorkerThread) ?
(w = (wt = (ForkJoinWorkerThread)t).workQueue).
tryUnpush(this) && (s = doExec()) < 0 ? s :
wt.pool.awaitJoin(w, this, 0L) :
externalAwaitDone();
}

Read More ...

JDK1.8的LongAdder分析

文档地址在这里 LongAdder Api

直接看代码

add
1
2
3
4
5
6
7
8
9
10
11
12
13
14
public void add(long x) {
Cell[] as; long b, v; int m; Cell a;
// cells非null或者在base上cas递增失败
if ((as = cells) != null || !casBase(b = base, b + x)) {
boolean uncontended = true;
if (as == null || (m = as.length - 1) < 0 ||
// getProbe()是个随机数,与m求与运算,能获得一个最小0最大m的数
(a = as[getProbe() & m]) == null ||
// 利用随机数,去cells上随机取一个Cell做CAS递增
!(uncontended = a.cas(v = a.value, v + x)))
// 如果递增失败,即出现竞争,调longAccumulate方法
longAccumulate(x, null, uncontended);
}
}

Read More ...

神奇的quasar

先埋个坑

https://github.com/puniverse/quasar
http://docs.paralleluniverse.co/quasar/
http://colobu.com/2016/07/14/Java-Fiber-Quasar/
http://geek.csdn.net/news/detail/71824
http://colobu.com/2016/08/01/talk-about-quasar-again/ (这个哥们的博客写的好,可以看一看)
http://geek.csdn.net/news/detail/71824(写的比较好,Vert.x 中的 vertx-sync 封装了 Quasar,很有意思~~)
https://www.jianshu.com/p/bc7d0d18e89f(vertx-sync)

比较有意思,是一个 Java 的协程实现,可以看看是怎么实现的。

再买几个坑:CompletableFuture、ForkJoinPool

Java的内存可见性

已知的 Java 内能保证内存可见性(能做到线程间通信)现在知道大致有这些:

Read More ...

ThreadPoolExecutor原理

ThreadPoolExecutor 源码

The main pool control state

属性 ctl 用来表示表示他内部的两个状态:工作线程数(workerCount),运行状态(runState):

1
2
3
4
5
6
7
/**
* The main pool control state, ctl, is an atomic integer packing
* two conceptual fields
* workerCount, indicating the effective number of threads
* runState, indicating whether running, shutting down etc
*/
private final AtomicInteger ctl = new AtomicInteger(ctlOf(RUNNING, 0));

Read More ...