在库存服务中实现缓存与数据库双写一致性

发布 : 2017-07-01 分类 : 大数据 浏览 :

markdown文档所采用图床为新浪微博图床

项目结构图

RequestProcessorThreadPool.java

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
package com.matrix.eshop.inventory.threadpool;

/**
* 请求处理线程池:单例
*
* @author matrix
*
*/
public class RequestProcessorThreadPool {

/**
* 静态内部类初始化单例-->绝对线程安全
*
* @author matrix
*
*/
private static class Singleton {

private static RequestProcessorThreadPool instance;

static {
instance = new RequestProcessorThreadPool();
}

public static RequestProcessorThreadPool getInstance() {
return instance;
}
}

/**
* 利用JVM的机制去保证多线程并发安全
*
* 内部类的初始化,一定只会发生一次,不管多少个线程并发去初始化
*
* @return
*/
public static RequestProcessorThreadPool getInstance() {
return Singleton.getInstance();
}
}
本文作者 : Matrix
原文链接 : https://matrixsparse.github.io/2017/07/01/在库存服务中实现缓存与数据库双写一致性/
版权声明 : 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明出处!

知识 & 情怀 | 二者兼得

微信扫一扫, 向我投食

微信扫一扫, 向我投食

支付宝扫一扫, 向我投食

支付宝扫一扫, 向我投食

留下足迹