1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package io.github.binglau;

import java.util.function.Supplier;

/**
* 文件描述: 懒加载大对象 Heavy
* 利用类加载机制达到 LazyLoad 为单例
*/

public final class LazyLoad {
private LazyLoad() {
}

private static class Holder {
private static final LazyLoad INSTANCE = new LazyLoad();
}

public static final LazyLoad getInstance() {
return Holder.INSTANCE;
}

private Supplier<Heavy> heavy = this::createAndCacheHeavy;
private Normal normal = new Normal();

public Heavy getHeavy() {
return heavy.get();
}

public Normal getNormal() {
return normal;
}

private synchronized Heavy createAndCacheHeavy() {
class HeavyFactory implements Supplier<Heavy> {
private final Heavy heavyInstance = new Heavy();
@Override
public Heavy get() {
return heavyInstance;
}
}

if (!HeavyFactory.class.isInstance(heavy)) {
heavy = new HeavyFactory();
}

return heavy.get();
}

public static void main(String[] args) throws InterruptedException {
LazyLoad.getInstance().getNormal();
LazyLoad.getInstance().getHeavy();
}

}

class Heavy {
public Heavy() {
System.out.println("Creating Heavy ...");
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("... Heavy created");
}
}

class Normal {
public Normal() {
System.out.println("Creating Normal ...");
System.out.println("... Normal created");
}
}

谈及 GC 自然是需要先谈及如何触发 GC,GC 作为垃圾回收器,自然是需要定义内存中『垃圾』的,那么怎么定义自然就成了关键。总体来说有以下的思路。

Read more »

动态路由器

动态路由器

动态路由器会使用规则,这些规则具有一定的复杂性。

Read more »

并行还是并发?

并发:同一时间应对多件事情的能力

并行:同一时间动手做多件事情的能力

并发与并行

Read more »

代理模式

动机

在某些情况下,一个客户不想或者不能直接引用一个对象,此时可以通过一个称之为“代理”的第三者来实现 间接引用。代理对象可以在客户端和目标对象之间起到 中介的作用,并且可以通过代理对象去掉客户不能看到的内容和服务或者添加客户需要的额外服务

Read more »

概述

Hash table and linked list implementation of the Map interface, with predictable iteration order. This implementation differs fromHashMap in that it maintains a doubly-linked list running through all of its entries. This linked list defines the iteration ordering, which is normally the order in which keys were inserted into the map (insertion-order). Note that insertion order is not affected if a key is re-inserted into the map. (A key k is reinserted into a map m if m.put(k, v) is invoked when m.containsKey(k) would return trueimmediately prior to the invocation.)

Read more »
0%