jersey
  1. jersey
  2. JERSEY-2431

"21.1. Implementing Custom Injection Provider" Instructions Can Lead to PermGen Error

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 2.6
    • Fix Version/s: backlog
    • Component/s: docs
    • Labels:
      None
    • Environment:

      JDK 7, Linux 32bit

      Description

      Section 21.1 of the documentation may have been intended to be generic instructions on how to create custom injection, unfortunately HttpSession use-case could lead to PermGen error. If the current instructions are followed injection of HttpSession result in the creation of a new proxy class every time. This can lead to PermGen error unless jvm class unloading is enabled (UseConcMarkSweepGC/CMSClassUnloadingEnabled jvm args). While this may seem reasonable a better solution is to proxy the HttpSession object and create it in the RequestScope.

      Change the documentation from this:

      import org.glassfish.hk2.utilities.binding.AbstractBinder;
      ...
       
      public class MyApplication extends ResourceConfig {
       
          public MyApplication() {
       
              ...
       
              register(new AbstractBinder() {
                  @Override
                  protected void configure() {
                      bindFactory(HttpSessionFactory.class).to(HttpSession.class);
                  }
              });
          }
      }
      

      to this:

      import org.glassfish.hk2.utilities.binding.AbstractBinder;
      ...
       
      public class MyApplication extends ResourceConfig {
       
          public MyApplication() {
       
              ...
       
              register(new AbstractBinder() {
                  @Override
                  protected void configure() {
                      bindFactory(HttpSessionFactory.class).to(HttpSession.class)
                           .proxy(true).proxyForSameScope(false).in(RequestScoped.class);
                  }
              });
          }
      }
      

      Note that WebComponentBinder class does the above for various request scoped objects (i.e. HttpServletRequest).

        Activity

        Hide
        saden added a comment -

        Perhaps the section can be split into two sections:
        a) Custom RequestScoped Injection Provider
        b) Custom HK2 Injection Provider.

        Show
        saden added a comment - Perhaps the section can be split into two sections: a) Custom RequestScoped Injection Provider b) Custom HK2 Injection Provider.
        Hide
        Michal Gajdos added a comment -

        Moving to backlog. Note: should be considered for the next release.

        Show
        Michal Gajdos added a comment - Moving to backlog. Note: should be considered for the next release.

          People

          • Assignee:
            Unassigned
            Reporter:
            saden
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated: