有没有办法获取 ClassLoader 加载了哪些类? [英] Is there a way to get which classes a ClassLoader has loaded?

查看:44
本文介绍了有没有办法获取 ClassLoader 加载了哪些类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为旧框架实施一些单元测试.我正在尝试模拟数据库层.不幸的是,我们的框架有点旧,没有完全使用最佳实践,因此没有明确的关注点分离.我有点担心尝试模拟数据库层可能会使 JVM 加载大量甚至不会使用的类.

I am trying to implement some unit testing for an old framework. I am attempting to mock out the database layer. Unfortunately our framework is a bit old and not quite using best practices so there is no clear separation of concerns. I am bit worried that trying to mock out the database layer might make the JVM load a huge number of classes that won't even be used.

我不太了解类加载器,所以这可能不是问题.有没有办法在特定 ClassLoader 加载的所有类上达到峰值,以证明幕后发生了什么?

I don't really understand class loaders that well so this might not be a problem. Is there a way to take a peak at all the classes a particular ClassLoader has loaded to prove what is going on under the hood?

推荐答案

注意使用

java -verbose

将产生大量的输出.将输出记录到文件中,然后使用 grep.如果你有tee"过滤器,你可以试试这个:

Will produce an enormous amount of output. Log the output to a file and then use grep. If you have the 'tee' filter you could try this:

java -verbose | tee classloader.log
grep class classloader.log

这篇关于有没有办法获取 ClassLoader 加载了哪些类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆