mirror of
https://github.com/Snailclimb/JavaGuide
synced 2025-08-01 16:28:03 +08:00
[docs fix] java基础-异常
This commit is contained in:
parent
0b83f6bc86
commit
e86dcf9ce6
@ -41,7 +41,7 @@ export default defineThemeConfig({
|
||||
// },
|
||||
pwa: {
|
||||
favicon: "/favicon.ico",
|
||||
cachePic: false,
|
||||
cachePic: true,
|
||||
cacheHTML: false,
|
||||
apple: {
|
||||
icon: "/assets/icon/apple-icon-152.png",
|
||||
|
@ -265,7 +265,17 @@ Catch Exception -> RuntimeException
|
||||
Finally
|
||||
```
|
||||
|
||||
**注意:不要在 finally 语句块中使用 return!** 当 try 语句和 finally 语句中都有 return 语句时,try 语句块中的 return 语句不会被执行。
|
||||
**注意:不要在 finally 语句块中使用 return!** 当 try 语句和 finally 语句中都有 return 语句时,try 语句块中的 return 语句会被忽略。这是因为 try 语句中的 return 返回值会先被暂存在一个本地变量中,当执行到 finally 语句中的 return 之后,这个本地变量的值就变为了 finally 语句中的 return 返回值。
|
||||
|
||||
[jvm 官方文档](https://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.html#jvms-4.10.2.5)中有明确提到:
|
||||
|
||||
> If the `try` clause executes a *return*, the compiled code does the following:
|
||||
>
|
||||
> 1. Saves the return value (if any) in a local variable.
|
||||
> 2. Executes a *jsr* to the code for the `finally` clause.
|
||||
> 3. Upon return from the `finally` clause, returns the value saved in the local variable.
|
||||
|
||||
先执行一部分的,先把返回的结果存到一段内存中;
|
||||
|
||||
示例:
|
||||
|
||||
|
@ -228,7 +228,7 @@ Thread[线程 2,5,main]waiting get resource1
|
||||
|
||||
避免死锁就是在资源分配时,借助于算法(比如银行家算法)对资源分配进行计算评估,使其进入安全状态。
|
||||
|
||||
**安全状态** 指的是系统能够按照某种进程推进顺序(P1、P2、P3.....Pn)来为每个进程分配所需资源,直到满足每个进程对资源的最大需求,使每个进程都可顺利完成。称<P1、P2、P3.....Pn>序列为安全序列。
|
||||
> **安全状态** 指的是系统能够按照某种线程推进顺序(P1、P2、P3.....Pn)来为每个线程分配所需资源,直到满足每个线程对资源的最大需求,使每个线程都可顺利完成。称<P1、P2、P3.....Pn>序列为安全序列。
|
||||
|
||||
我们对线程 2 的代码修改成下面这样就不会产生死锁了。
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user