问题描述
我正在使用Eclipse WTP作为项目。它需要使用很少的库。几个体积小,少数较大。我的问题是,当我们在servlet中使用外部jar时会发生什么?如果我在Servlet中导入了一个重量级的库,它会影响网页加载时间吗?或者Java只是编译我的程序,包括库来提供结果。我知道重型jar将需要一些时间来加载我的本地机器,但我可以管理它们只被启动一次(通过创建一个单独的类,并启动静态变量并使用它们从其他类)。但是似乎这样,这不能在Servlet中完成,并且每次加载一个页面时,servlet都必须加载所有那些沉重的jar。
在Servlets中使用Guava和Solrj是否很好?他们放慢了(询问,因为我觉得Solrj正在减缓网页加载时间)?
本身并没有减慢servlet的运行时间。但是,在jar中使用特定的工具/类/功能可能会减慢servlet,具体取决于您正在尝试的操作。
我建议使用分析器来分析你的代码实际上决定了它导致的减速。 的报价:
I am using Eclipse WTP for a project. It requires few libraries to be used. Few are small in size and few are larger. My question is, what happens when we use external jars in servlets ? If I am importing a heavy-weight library in a Servlet, does it impacts webpage load time ?
Or Java just compiles my program including libraries to give results. I understand heavy-weight jar will take time to load once even on my local machine, but I can manage them to be initiated only once (by creating a separate class and initiate static variables and use them from other classes). But seems like, this can't be done in Servlets and every time a page is loaded, servlet has to load all those heavy jars.
Is it good to use Guava and Solrj in Servlets ? Do they slow down (asking because I feel Solrj is slowing down webpage load time) ?
Including a jar in-and-of itself does not slow down servlet run time. However, using a particular tool/class/functionality in a jar may slow down the servlet, depending on what you are trying to do.
I recommend using a profiler to analyze your code and actually determine what it causing the slowdown. Here's a quote from Martin Fowler's Refactoring:
这篇关于通过在servlet中使用外部jar来影响性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!