Java:hasJREfinishedInitialization() - 如何检查jre是否已完成加载/初始化所有核心类?
有没有办法检查所有引导(核心)java类(属于Java运行时环境)是否已加载/初始化以在Java中使用?
在一种罕见的情况下,我需要检查这一点,即我可以访问 JRE 但不能访问实际应用程序,因此我不能简单地等待主应用程序从那时起运行和执行。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
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.阅读了您的评论(并意外删除了我的 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?