Skip to content

Commit b5f8894

Browse files
committed
[docs fix]修正链接错误&基本类型和包装类型的区别
1 parent a6cf71b commit b5f8894

File tree

5 files changed

+22
-19
lines changed

5 files changed

+22
-19
lines changed

docs/cs-basics/algorithms/the-sword-refers-to-offer.md

+1-4
Original file line numberDiff line numberDiff line change
@@ -622,10 +622,7 @@ public class Solution {
622622

623623
**题目分析:**
624624

625-
这道题想了半天没有思路,参考了 Alias 的答案,他的思路写的也很详细应该很容易看懂。
626-
作者:Alias
627-
<https://www.nowcoder.com/questionTerminal/d77d11405cc7470d82554cb392585106>
628-
来源:牛客网
625+
这道题想了半天没有思路,参考了 [Alias 的答案](https://www.nowcoder.com/questionTerminal/d77d11405cc7470d82554cb392585106),他的思路写的也很详细应该很容易看懂。
629626

630627
【思路】借用一个辅助的栈,遍历压栈顺序,先讲第一个放入栈中,这里是 1,然后判断栈顶元素是不是出栈顺序的第一个元素,这里是 4,很显然 1≠4,所以我们继续压栈,直到相等以后开始出栈,出栈一个元素,则将出栈顺序向后移动一位,直到不相等,这样循环等压栈顺序遍历完成,如果辅助栈还不为空,说明弹出序列不是该栈的弹出顺序。
631628

docs/java/basis/java-basic-questions-01.md

+13-3
Original file line numberDiff line numberDiff line change
@@ -452,11 +452,21 @@ Java 中有 8 种基本数据类型,分别为:
452452

453453
**为什么说是几乎所有对象实例都存在于堆中呢?** 这是因为 HotSpot 虚拟机引入了 JIT 优化之后,会对对象进行逃逸分析,如果发现某一个对象并没有逃逸到方法外部,那么就可能通过标量替换来实现栈上分配,而避免堆上分配内存
454454

455-
⚠️ 注意:**基本数据类型存放在栈中是一个常见的误区!** 基本数据类型的成员变量如果没有被 `static` 修饰的话(不建议这么使用,应该要使用基本数据类型对应的包装类型),就存放在堆中
455+
⚠️ 注意:**基本数据类型存放在栈中是一个常见的误区!** 基本数据类型的存储位置取决于它们的作用域和声明方式。如果它们是局部变量,那么它们会存放在栈中;如果它们是成员变量,那么它们会存放在堆中
456456

457457
```java
458-
class BasicTypeVar{
459-
private int x;
458+
public class Test {
459+
// 成员变量,存放在堆中
460+
int a = 10;
461+
// 被 static 修饰,也存放在堆中,但属于类,不属于对象
462+
// JDK1.7 静态变量从永久代移动了 Java 堆中
463+
static int b = 20;
464+
465+
public void method() {
466+
// 局部变量,存放在栈中
467+
int c = 30;
468+
static int d = 40; // 编译错误,不能在方法中使用 static 修饰局部变量
469+
}
460470
}
461471
```
462472

docs/java/basis/java-basic-questions-02.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -431,8 +431,8 @@ public boolean equals(Object anObject) {
431431

432432
> ⚠️ 注意:该方法在 **Oracle OpenJDK8** 中默认是 "使用线程局部状态来实现 Marsaglia's xor-shift 随机数生成", 并不是 "地址" 或者 "地址转换而来", 不同 JDK/VM 可能不同在 **Oracle OpenJDK8** 中有六种生成方式 (其中第五种是返回地址), 通过添加 VM 参数: -XX:hashCode=4 启用第五种。参考源码:
433433
>
434-
> - <https://hg.openjdk.org/jdk8u/jdk8u/hotspot/file/87ee5ee27509/src/share/vm/runtime/globals.hpp(1127> 行)
435-
> - <https://hg.openjdk.org/jdk8u/jdk8u/hotspot/file/87ee5ee27509/src/share/vm/runtime/synchronizer.cpp(537> 行开始)
434+
> - <https://hg.openjdk.org/jdk8u/jdk8u/hotspot/file/87ee5ee27509/src/share/vm/runtime/globals.hpp>(1127 行)
435+
> - <https://hg.openjdk.org/jdk8u/jdk8u/hotspot/file/87ee5ee27509/src/share/vm/runtime/synchronizer.cpp>(537 行开始)
436436
437437
```java
438438
public native int hashCode();

docs/java/collection/arrayblockingqueue-source-code.md

+2-3
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ public E poll() {
546546
//上锁
547547
lock.lock();
548548
try {
549-
//如果队列为空直接返回null,反之出队返回元素值
549+
//如果队列为空直接返回null,反之出队返回元素值
550550
return (count == 0) ? null : dequeue();
551551
} finally {
552552
lock.unlock();
@@ -558,13 +558,12 @@ public E poll() {
558558

559559
```java
560560
public boolean add(E e) {
561-
//调用下方的add
562561
return super.add(e);
563562
}
564563

565564

566565
public boolean add(E e) {
567-
//调用offer如果失败直接抛出异常
566+
//调用offer方法如果失败直接抛出异常
568567
if (offer(e))
569568
return true;
570569
else

docs/java/concurrent/java-thread-pool-best-practices.md

+4-7
Original file line numberDiff line numberDiff line change
@@ -91,33 +91,30 @@ ExecutorService threadPool = new ThreadPoolExecutor(corePoolSize, maximumPoolSiz
9191
**2、自己实现 `ThreadFactory`**
9292

9393
```java
94-
import java.util.concurrent.Executors;
9594
import java.util.concurrent.ThreadFactory;
9695
import java.util.concurrent.atomic.AtomicInteger;
96+
9797
/**
9898
* 线程工厂,它设置线程名称,有利于我们定位问题。
9999
*/
100100
public final class NamingThreadFactory implements ThreadFactory {
101101

102102
private final AtomicInteger threadNum = new AtomicInteger();
103-
private final ThreadFactory delegate;
104103
private final String name;
105104

106105
/**
107106
* 创建一个带名字的线程池生产工厂
108107
*/
109-
public NamingThreadFactory(ThreadFactory delegate, String name) {
110-
this.delegate = delegate;
111-
this.name = name; // TODO consider uniquifying this
108+
public NamingThreadFactory(String name) {
109+
this.name = name;
112110
}
113111

114112
@Override
115113
public Thread newThread(Runnable r) {
116-
Thread t = delegate.newThread(r);
114+
Thread t = new Thread(r);
117115
t.setName(name + " [#" + threadNum.incrementAndGet() + "]");
118116
return t;
119117
}
120-
121118
}
122119
```
123120

0 commit comments

Comments
 (0)