title: Why filter is initialized twice?
body: <p>I have implemented a filter as below - </p>
  
  <pre><code>import javax.annotation.PostConstruct;
  import javax.inject.Inject;
  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.annotation.WebFilter;
  import javax.servlet.http.Cookie;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  import javax.servlet.http.HttpSession;
  import javax.ws.rs.container.ContainerRequestContext;
  import javax.ws.rs.container.ContainerRequestFilter;
  import javax.ws.rs.container.ContainerResponseContext;
  import javax.ws.rs.container.ContainerResponseFilter;
  
  @WebFilter("/login.jsf")
  public class ServiceFilter implements ContainerRequestFilter, ContainerResponseFilter, Filter {
  
  public ServiceFilter() {}
  
  @PostConstruct
  public void init() {
      logger.debug("initialized.");
  }
  @Override
  public void destroy() {
      logger.debug("destroyed");
  }
  
  @Override
  public void init(FilterConfig arg0) throws ServletException {
  //nothing here
  }
  ...other method overides
  }
  </code></pre>
  
  <p>When I deploy it on <code>Wildfly10</code>, I see the below gets printed </p>
  
  <pre><code>TIMESTAMP DEBUG ServiceFilter:65 - Initialized (ServiceFilter@39df1f0b)
  TIMESTAMP DEBUG ServiceFilter:65 - Initialized (ServiceFilter@1a33dd9)
  </code></pre>
  
  <p><code>ServiceFilter</code> class is also registered as a root resource in one of the class which implements <code>javax.ws.rs.core.Application</code>. This class acts as an entry point for rest and web resources.</p>
  
  <p>How can I avoid the <code>ServiceFilter</code> class from being initialized twice? Or, is this okay as the filter implements both servlet and rest filters? Or, should I move the implementation in their own class files?</p>
  
  <p>PS: The above stated behavior doesn't actually hinder any functionality offered by my application (I think and could be otherwise) but just wanted to make sure that I'm doing it right.</p>