Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 2 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,28 +37,11 @@
# Spring大家族

#### `Spring`
`历史(有关Spring的历史)`
* [Spring历史版本以及现在的帝国](http://note.youdao.com/noteshare?id=80509c0296c54ccb86c1848b95c9c530)
* [为什么要有Spring 这里主要是引入Spring IOC](http://note.youdao.com/noteshare?id=a61d1330cec20afe21d369f0526756a2)
* [为什么要有Spring AOP](http://note.youdao.com/noteshare?id=21f2b64abb67a24ad45baca5456648a5)
[Spring4基础知识系列](java/spring/spring.md)

`控制反转`
* [手写一个Spring IOC的简单实现](https://github.com/zhonghuasheng/JAVA/tree/master/basic/src/main/java/com/zhonghuasheng/ioc)
* [Spring注解大全](java/spring/spring.md/#Spring注解)

`依赖注入`
* [Spring依赖注入之Setter注入 - Setter Injection](https://github.com/zhonghuasheng/JAVA/tree/master/spring4/src/main/java/com/zhonghuasheng/spring4/springdiwithxmlexample/setterinject)
* [Spring依赖注入之构造函数注入 - Constructor Injection](https://github.com/zhonghuasheng/JAVA/tree/master/spring4/src/main/java/com/zhonghuasheng/spring4/springdiwithxmlexample/constructorinject)
* [Spring自动装配]() ***[byName](https://github.com/zhonghuasheng/JAVA/tree/master/spring4/src/main/java/com/zhonghuasheng/spring4/autowiringusingxml/autowirebyname)*** ***[byType](https://github.com/zhonghuasheng/JAVA/tree/master/spring4/src/main/java/com/zhonghuasheng/spring4/autowiringusingxml/autowirebytype)***
***[constructor](https://github.com/zhonghuasheng/JAVA/tree/master/spring4/src/main/java/com/zhonghuasheng/spring4/autowiringusingxml/constructor)***
***[no](https://github.com/zhonghuasheng/JAVA/tree/master/spring4/src/main/java/com/zhonghuasheng/spring4/autowiringusingxml/no)***
* [Spring通过注解实现自动装配-example1](https://github.com/zhonghuasheng/JAVA/tree/master/spring4/src/main/java/com/zhonghuasheng/spring4/annotationinjectexample)
***[@Resource](https://github.com/zhonghuasheng/JAVA/tree/master/spring4/src/main/java/com/zhonghuasheng/spring4/annotationinjectexample/resource)***
***[@Qualifier](https://github.com/zhonghuasheng/JAVA/tree/master/spring4/src/main/java/com/zhonghuasheng/spring4/annotationinjectexample/qualifier)***
***[@Autowired](https://github.com/zhonghuasheng/JAVA/tree/master/spring4/src/main/java/com/zhonghuasheng/spring4/annotationinjectexample/autowired)***
* [Spring通过注解实现自动装配-example2-@Service @Repository的使用](https://github.com/zhonghuasheng/JAVA/tree/master/spring4/src/main/java/com/zhonghuasheng/spring4/autodetection)


#### `Spring Boot`
* [SpringBoot历史](spring-boot/0-springboot-history.md)
* [SpringBoot基础](spring-boot/1-springboot-basic.md)
Expand Down Expand Up @@ -258,6 +241,6 @@
<h2 align="center">技术栈</h2>
<center>

![](tutorial-2020-02-18.png)
![](tutorial-2020-02-21.png)

</center>
5 changes: 4 additions & 1 deletion english/english.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,7 @@
* demultiplexer 信号分离器,多路分配器 reactor模式中的名词
* allocator 分配者
* Cache Hit Ratio 缓存命中率,MyBatis中二级缓存log会输出
* chunk 块,大块
* chunk 块,大块
* fair 合理的,公正的
* reentrant 可重入的
* AQS AbstractQueuedSynchronizer类,是Java中独占锁和共享锁的公共父类,锁的许多公共方法都是在这个类中实现
21 changes: 20 additions & 1 deletion java/basic/java-thread-juc.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,25 @@ CAS(比较并交换)是`CPU指令级`的操作,只有一步原子操作,
* 只能保证一个共享变量的原子操作

## Unsafe类解读
* Unsafe类是在sun.misc包下,不属于Java标准。但是很多Java的基础类库,包括一些被广泛使用的高性能开发库都是基于Unsafe类开发的,比如Netty、Hadoop、Kafka等。
* Unsafe类是在sun.misc包下,不属于Java标准。该类封装了许多类似指针操作,可以直接进行内存管理、操纵对象、阻塞/唤醒线程等操作。Java本身不直接支持指针的操作,所以这也是该类命名为Unsafe的原因之一。但是很多Java的基础类库,包括一些被广泛使用的高性能开发库都是基于Unsafe类开发的,比如Netty、Hadoop、Kafka等。
* 使用Unsafe可用来直接访问系统内存资源并进行自主管理,Unsafe类在提升Java运行效率,增强Java语言底层操作能力方面起了很大的作用。
* Unsafe可认为是Java中留下的后门,提供了一些低层次操作,如直接内存访问、线程调度等。
* 官方并不建议使用Unsafe。

J.U.C中的许多CAS方法,内部其实都是Unsafe类在操作。
比如AtomicBoolean的compareAndSet方法:
```java
public final boolean compareAndSet(boolean expect, boolean update) {
int e = expect ? 1 : 0;
int u = update ? 1 : 0;
return unsafe.compareAndSwapInt(this, valueOffset, e, u);
}
compareAndSwapInt(Object o, long offset, int expected, int x);
// o是需要修改的对象 offset需要修改的字段到对象头的偏移量(通过偏移量可以快速定位修改的是哪个字段) expected 期望值 x要设置的值
```

unsafe.compareAndSwapInt方法是个native方法。(如果对象中的字段值与期望值相等,则将字段值修改为x,然后返回true;否则返回false):

> Unsafe的大部分API都是native的方法,主要包括以下几类:
1. Class相关。主要提供Class和它的静态字段的操作方法。
2. Object相关。主要提供Object和它的字段的操作方法。
Expand Down Expand Up @@ -120,7 +134,12 @@ AtomicLong是作用是对长整形进行原子操作。在32位操作系统中

#### 数组类型
AtomicIntegerArray, AtomicLongArray, AtomicReferenceArray三个数组类型的原子类,原理和用法都是类似的。
这三种类型大同小异,AtomicIntegerArray对应AtomicInteger,AtomicLongArray对应AtomicLong,AtomicReferenceArray对应AtomicReference。
AtomicLong是作用是对长整形进行原子操作。而AtomicLongArray的作用则是对"长整形数组"进行原子操作。
unsafe是通过Unsafe.getUnsafe()返回的一个Unsafe对象。通过Unsafe的CAS函数对long型数组的元素进行原子操作。
其实阅读源码也可以发现,这些数组原子类与对应的普通原子类相比,只是多了通过索引找到内存中元素地址的操作而已。
注意:原子数组并不是说可以让线程以原子方式一次性地操作数组中所有元素的数组。而是指对于数组中的每个元素,可以以原子方式进行操作。



# 引用
Expand Down
70 changes: 39 additions & 31 deletions java/spring/spring.md
Original file line number Diff line number Diff line change
@@ -1,37 +1,45 @@
`目录`
# Spring
http://blog.csdn.net/yangyangiud/article/details/52368712
## Factory Pattern
### Simple Factory
### Factory Method
### Abstract Factory
## Spring
* [为什么要有Spring](http://note.youdao.com/noteshare?id=a61d1330cec20afe21d369f0526756a2&sub=wcp1556526473148138)
* [为什么要有Spring AOP](http://note.youdao.com/noteshare?id=21f2b64abb67a24ad45baca5456648a5&sub=wcp1556587241813493)
* [关于Spring IOC和AOP的理解](http://note.youdao.com/noteshare?id=d0aa79a9af96f02aad6e25c1d3f192b3&sub=wcp1582173498187944)
* [Spring历史版本变迁和如今的生态帝国](http://note.youdao.com/noteshare?id=80509c0296c54ccb86c1848b95c9c530&sub=wcp15565934311825)
* [手写一个Spring IOC的简单实现](https://github.com/zhonghuasheng/JAVA/tree/master/basic/src/main/java/com/zhonghuasheng/ioc)
* [什么是Spring]()
* [Spring 依赖注入](http://note.youdao.com/noteshare?id=91ac0b573c1898e8fa3b47ebfdfffbf1&sub=wcp1582257498880783)
* [Spring Java配置](http://note.youdao.com/noteshare?id=4808a867c7b646f7f4d41a1bbe2f79fa&sub=wcp1582272695540930)
* [Spring Bean Scope](http://note.youdao.com/noteshare?id=f0c541d742d9548342dbca9e04607758&sub=wcp1582292894805554)
* [Spring AOP与AspectJ的对比](http://note.youdao.com/noteshare?id=b75baf23ad8073d69527838449b259c1&sub=wcp1582290319293279)


### 依赖注入
Spring IoC容器(ApplicationContext)负责创建Bean,并通过容器将功能类Bean注入到你需要的Bean中。Spring提供使用xml,注解,Java配置,groovy配置实现Bean的创建和注入。
无论是xml配置,注解配置还是Java配置,都被称为配置元数据,所谓元数据即描述数据的数据。元数据本身不具备任何可执行的能力,只能通过外界代码来对这些元数据行解析后进行一些有意义的操作。Spring容器解析这些配置元数据进行Bean初始化,配置和管理依赖。
> 声明Bean的注解:
@Component 组件,没有明确的角色。
@Service 在业务逻辑层(service层)使用。
@Repository 在数据访问层(dao层)使用。
@Controller在展现层(MVC——>SpringMVC)使用。

> 注入Bean的注解,一般情况下通用
@Autowired:Spring提供的注解。
@Inject:JSR-330提供的注解。
@Resource:JSR-250提供的注解。

@Autowired,@Inject,@Resource可注解在set方法或者属性上

* [Spring依赖注入之Setter注入 - Setter Injection](https://github.com/zhonghuasheng/JAVA/tree/master/spring4/src/main/java/com/zhonghuasheng/spring4/springdiwithxmlexample/setterinject)
* [Spring依赖注入之构造函数注入 - Constructor Injection](https://github.com/zhonghuasheng/JAVA/tree/master/spring4/src/main/java/com/zhonghuasheng/spring4/springdiwithxmlexample/constructorinject)
* [Spring自动装配]() ***[byName](https://github.com/zhonghuasheng/JAVA/tree/master/spring4/src/main/java/com/zhonghuasheng/spring4/autowiringusingxml/autowirebyname)*** ***[byType](https://github.com/zhonghuasheng/JAVA/tree/master/spring4/src/main/java/com/zhonghuasheng/spring4/autowiringusingxml/autowirebytype)***
***[constructor](https://github.com/zhonghuasheng/JAVA/tree/master/spring4/src/main/java/com/zhonghuasheng/spring4/autowiringusingxml/constructor)***
***[no](https://github.com/zhonghuasheng/JAVA/tree/master/spring4/src/main/java/com/zhonghuasheng/spring4/autowiringusingxml/no)***
* [Spring通过注解实现自动装配-example1](https://github.com/zhonghuasheng/JAVA/tree/master/spring4/src/main/java/com/zhonghuasheng/spring4/annotationinjectexample)
***[@Resource](https://github.com/zhonghuasheng/JAVA/tree/master/spring4/src/main/java/com/zhonghuasheng/spring4/annotationinjectexample/resource)***
***[@Qualifier](https://github.com/zhonghuasheng/JAVA/tree/master/spring4/src/main/java/com/zhonghuasheng/spring4/annotationinjectexample/qualifier)***
***[@Autowired](https://github.com/zhonghuasheng/JAVA/tree/master/spring4/src/main/java/com/zhonghuasheng/spring4/annotationinjectexample/autowired)***
* [Spring通过注解实现自动装配-example2-@Service @Repository的使用](https://github.com/zhonghuasheng/JAVA/tree/master/spring4/src/main/java/com/zhonghuasheng/spring4/autodetection)

## IOC/DI
### IOC简介
### 注入方式(常用的有三种)
### IOC实现基本原理

## AOP
### AOP引入
### JDK代理
### CGLib代理
### 模拟Spring-IOC
### 模拟Spring-AOP

## Spring 基础
### Hello Spring
### Spring Singleton
### Spring Factory Method
### Spring Inject Method

## Spring Liferay Cycle
## Spring Autowire
## Abstract Parent Import
## Spring Annotation
## Spring Collections

### Spring AOP
#### Spring AOP引入

`正文`

Expand Down
Binary file removed tutorial-2020-02-18.png
Binary file not shown.
Binary file added tutorial-2020-02-21.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.