过滤器是否有任何原因会减慢服务器响应?
我有一个带有以下过滤器的网络应用程序:
package com.bingo.filters;
import java.io.IOException;
import java.util.Arrays;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpServletResponseWrapper;
public class CacheFilter implements Filter {
static class CacheControlHeaderResponse extends HttpServletResponseWrapper {
public static final String[] CACHEABLE_CONTENT_TYPES = new String[] {
"text/css", "text/javascript", "image/png", "image/jpeg",
"image/gif", "image/jpg" };
static {
Arrays.sort(CACHEABLE_CONTENT_TYPES);
}
public CacheControlHeaderResponse(HttpServletResponse response) {
super(response);
}
@Override
public void setContentType(String contentType) {
super.setHeader("Expires", "-1");
super.setHeader("Cache-Control", "no-store, no-cache, must-revalidate");
super.setHeader("Pragma", "no-cache");
super.setContentType(contentType);
}
}
public CacheFilter() {
}
public void destroy() {
}
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
HttpServletRequest req = (HttpServletRequest) request;
HttpServletResponse res = (HttpServletResponse) response;
chain.doFilter(request, new CacheControlHeaderResponse(res));
}
public void init(FilterConfig fConfig) throws ServletException {
}
}
这是我添加到 web.xml 中的配置
<filter>
<filter-name>cFilter</filter-name>
<filter-class>com.bingo.filters.CacheFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>cFilter</filter-name>
<url-pattern>/bingo/*</url-pattern>
</filter-mapping>
当我使用这个新代码部署战争时,应用程序服务器的响应速度非常慢。检索页面需要 6 或 7 秒。
但是如果我在没有上面代码的情况下部署旧的war文件,那么响应非常快。
上面的代码有什么问题可以解释性能问题吗?