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

查看:87
本文介绍了有没有办法让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天全站免登陆