eclipse-ee4j / eclipse-ee4j/jersey

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

Open
#2,703 5 comments 0 reactions 0 assignees View on GitHub
Component: docs Priority: Major Type: Bug
Dominant language
Java
Stars
730
Forks
382
PR merge metrics
No merged PRs in 30d

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).
#### Environment
JDK 7, Linux 32bit
#### Affected Versions
[2.6]

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.