gpt4 book ai didi

java - "during the operation of the Java Virtual Machine"的定义是什么?

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:02:04 27 4
gpt4 key购买 nike

来自 JVMS chapter 6.3 :

[...] any of the VirtualMachineError subclasses defined below [InternalError, OutOfMemoryError, StackOverflowError, UnknownError] may be thrown at any time during the operation of the Java Virtual Machine

JVMS如何定义“在Java虚拟机运行期间的任何时候”这句话?

当前的 JVM 如何解释该短语?

具体是不是表示这四个错误,java.lang.InternalError , java.lang.OutOfMemoryError , java.lang.StackOverflowError , 和 java.lang.UnknownError , 可能会被抛出 between 语句? :

// ....
A(); B(); C();
try {
// nothing
} catch (InternalError | OutOfMemoryError | StackOverflowError | UnknownError e) {
// may occur?
}
D(); E(); F();
try {
; // semi-colon
} catch (InternalError | OutOfMemoryError | StackOverflowError | UnknownError e) {
// may occur?
}
G(); H(); I();
try {
; ; ;; ;;;;; ; ; ;;; ;; ;; ;; ;; ; ;; ; ;; // ... semi-colons
} catch (InternalError | OutOfMemoryError | StackOverflowError | UnknownError e) {
// may occur?
}
J(); K(); L();
// ....

最佳答案

Java 虚拟机由许多部分组成。例如,垃圾收集器作为持久后台 Thread 运行。它可能会抛出其中一个 Exception 并且它肯定会随时发生(尤其是当您自己的代码由于 gc 而停止时)!

来自 Java Garbage Collection Basics

What is Automatic Garbage Collection?

Automatic garbage collection is the process of looking at heap memory, identifying which objects are in use and which are not, and deleting the unused objects. An in use object, or a referenced object, means that some part of your program still maintains a pointer to that object. An unused object, or unreferenced object, is no longer referenced by any part of your program. So the memory used by an unreferenced object can be reclaimed.

tl;dr

是的。它们可以放在语句之间。

关于java - "during the operation of the Java Virtual Machine"的定义是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27679158/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com