Is there any way to judge whether a class has been loaded into jvm?
In my opinion,I think the way is findClass
,is that right?
Asked
Active
Viewed 129 times
2

flower
- 2,212
- 3
- 29
- 44
-
This depends on what you requirements are. Is it when the class is searched for, loaded via byte code and thus has a `.class` object, or when it's initialised? – Peter Lawrey Apr 10 '17 at 06:51
-
May be it is loaded,and then is deleted .So I think I can not judge from the object class,such as aop mechanism. – flower Apr 10 '17 at 06:58
-
3The real question is probably: why do you think that matters? In other words: what is the problem you intend to solve by doing such a judgement? – GhostCat Apr 10 '17 at 07:01
-
I was asked from an interview.I still can not figure out. – flower Apr 10 '17 at 07:19
3 Answers
1
OK, so I have not done this. But it seems that it would be possible via getAllLoadedClasses()
in the Instrumentation API.
But then you would still need to start the JVM with your agent
.

Eugene
- 117,005
- 15
- 201
- 306
-
Depending on the JVM, you may load agents after the start dynamically, e.g. via the Attach API. At the end of [this answer](http://stackoverflow.com/a/19912148/2711488) is an example program that attaches to its own JVM to load itself as agent to finally get hands on the `Instrumentation` API. – Holger Apr 24 '17 at 23:25
0
Turn on class loader logging with -verbose:class
and read the log.

Joni
- 108,737
- 14
- 143
- 193
-
1what if you have already started the JVM and it is running at the moment? – Eugene Apr 10 '17 at 08:14