如果我在项目中使用了反射堆,ehcache是​​否比反射快? [英] Is ehcache faster then reflection if I have use heaps of reflection in my project?

查看:73
本文介绍了如果我在项目中使用了反射堆,ehcache是​​否比反射快?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须在项目中使用反射堆,例如getDeclaredFields或isAnnotationPresent之类的东西,是否应该使用ehcache来缓存结果?

I have to use heaps of reflection in my project, like getDeclaredFields or isAnnotationPresent something like that, should I use ehcache to cache the result? will it help?

推荐答案

正如Drekka提到的那样,我确实要先衡量一下。那是您应该考虑的一般规则。现在关于这里的问题,您应该知道java.lang.Class类实际上已经实现了针对此类调用的缓存机制。根据确切的访问模式,机会很高,您自己缓存结果将不会获得任何性能。

As Drekka mentions it, I'd measure first indeed. That's something you should consider a general rule. Now with regards to the question at hand here, you should know that the java.lang.Class class actually already implements caching mechanism for these sort of calls. Depending on the exact access patterns, chances are very high you would not gain any performance by caching the results yourself.

这篇关于如果我在项目中使用了反射堆,ehcache是​​否比反射快?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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