Java:hasJREfinishedInitialization() - 如何检查jre是否已完成加载/初始化所有核心类?

发布于 2024-08-30 02:15:35 字数 135 浏览 5 评论 0 原文

有没有办法检查所有引导(核心)java类(属于Java运行时环境)是否已加载/初始化以在Java中使用?

在一种罕见的情况下,我需要检查这一点,即我可以访问 JRE 但不能访问实际应用程序,因此我不能简单地等待主应用程序从那时起运行和执行。

Is there a way to check if all boot (core) java classes (belonging to the Java Runtime Environment) have been loaded/initialized for use in Java?

I need to check this in a rare situation where I have have access to the JRE but not to the actual application, so I cannot simply wait for the main application to run and execute from that point on.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

Oo萌小芽oO 2024-09-06 02:15:35

JVM 将“根据需要”加载类,因此引导类路径上的“所有”类都不会在某一时刻被加载。

也就是说,从 1.5 及更高版本开始,Sun JVM 使用“类数据共享”来预加载一组特定的类。我不知道加载哪些类,但怀疑它仅限于 java.lang 包中的类。

如果您只是想跟踪类的加载时间,请在启动 JVM 时使用 -verbose:class 命令行选项。

The JVM will load classes on an "as-needed" basis, so there's no one point at which "all" of the classes on the bootstrap classpath will have been loaded.

That said, from 1.5 and onward, the Sun JVMs use "class data sharing" to pre-load a specific set of classes. I don't know which classes get loaded, but would suspect it's limited to those in the java.lang package.

If you simply want to keep track of when classes get loaded, use the -verbose:class command-line option when starting the JVM.

雨的味道风的声音 2024-09-06 02:15:35

阅读了您的评论(并意外删除了我的 cookie),我只能说 JVMTI 几乎肯定是一个更好的选择。

但是,如果您一心想要修改 JRE 类,为什么不简单地添加一个将在 FileWriter 初始化期间设置的静态布尔变量呢?

having read your comments (and accidentally deleted my cookie), all I can say is that JVMTI is pretty much guaranteed to be a much better choice for whatever it is that you're trying to do.

But if you're hell-bent on modifying a JRE class, why not simply add a static boolean variable that will get set during FileWriter initialization?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文