Skip to content

Commit

Permalink
finished all
Browse files Browse the repository at this point in the history
  • Loading branch information
Q10Viking committed Mar 16, 2024
1 parent 1ae78b6 commit c081d31
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 3 deletions.
2 changes: 1 addition & 1 deletion docs/JVM/21 静态初始化类启动线程问题分析.md
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ public static CallSite metafactory(MethodHandles.Lookup caller,
> java -Djdk.internal.lambda.dumpProxyClasses MainTest
> ```

生成的匿名内部类
生成的**匿名内部类**

```java
import java.lang.invoke.LambdaForm.Hidden;
Expand Down
8 changes: 8 additions & 0 deletions docs/concurrency/47 线程间的通信.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,14 @@ ObjectMonitor中有两个队列,**_WaitSet 和 _EntryList**,用来保存Obje

> notify/notifyAll/wait等方法会使用到Monitor锁对象,所以必须在同步代码块中使用
在Java中,notify()和notifyAll()都属于Object类的方法,用于实现线程间的通信。

**notify()方法**用于唤醒在当前对象上等待的单个线程。如果有多个线程同时在某个对象上等待(通过调用该对象的wait()方法),则只会唤醒其中一个线程,并使其从等待状态变为可运行状态。具体是哪个线程被唤醒是不确定的,取决于线程调度器的实现。

**notifyAll()方法**用于唤醒在当前对象上等待的所有线程。如果有多个线程在某个对象上等待,调用notifyAll()方法后,所有等待的线程都会被唤醒并竞争该对象的锁。其中一个线程获得锁后继续执行,其他线程则继续等待。

需要注意的是,notify()和notifyAll()方法只能在同步代码块或同步方法内部调用,并且必须拥有与该对象关联的锁。否则会抛出IllegalMonitorStateException异常。

[Source Code](https://github.com/Q10Viking/learncode/blob/main/concurrency/src/main/java/org/hzz/basic/communicate/WaitDemo.java)

```java
Expand Down
4 changes: 4 additions & 0 deletions docs/java/14 hash & equals 对象集合求交集.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ typora-root-url: ..\.vuepress\public


> 在看nacos服务注册时,求服务实例集合的交集
>
> equals相等,则hashCode一定相等;
>
> hashCode相等,则equals不一定相等(哈希冲突)
## 重写hashcode与equals方法

Expand Down
4 changes: 4 additions & 0 deletions docs/java/19 变量.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,7 @@ public class TestFinal {
}
```

## 内存空间

- - 变量在内存中占用一块存储空间,可以改变这个存储空间中的值。
- 常量通常会被编译器在编译时直接替换为对应的值,所以在内存中不会为常量分配额外的存储空间,而是直接使用常量的值。
7 changes: 6 additions & 1 deletion docs/java/39 final关键字.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ typora-root-url: ..\.vuepress\public
}
```


- 修饰变量:表示变量一旦被赋值就不可以更改它的值。


Expand Down Expand Up @@ -152,3 +151,9 @@ public class OutClass {





## finally什么场景不会被执行

比较极端的调用,`System.exit(0)`

6 changes: 5 additions & 1 deletion docs/java/40 String StringBuffer StringBuilder.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ public synchronized int length() {

## StringBuilder线程不安全演示

- 扩容时会数组越界
- 添加字符时会出现覆盖

```java
public class StringBuilderNotSafeDemo {
public static void main(String[] args) throws InterruptedException {
Expand Down Expand Up @@ -155,4 +158,5 @@ ensureCapacityInternal(count + len); // 线程不安全,多个线程都读取

[ProgressOn](https://www.processon.com/view/link/645cc06be18d2f06805c8d20)

![StringBuilder线程不安全的原因](/images/java/StringBuilder线程不安全的原因.png)
![StringBuilder线程不安全的原因](/images/java/StringBuilder线程不安全的原因.png)

0 comments on commit c081d31

Please sign in to comment.