Skip to content
This repository was archived by the owner on May 28, 2018. It is now read-only.

Commit 2ccb947

Browse files
japodpavelbucek
authored andcommitted
Clearing HK2 locator caches after the locator is initialised.
Change-Id: I3379c7914e95bf36191d672fef1820efb03f8829 Signed-off-by: Jakub Podlesak <[email protected]>
1 parent c80d563 commit 2ccb947

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

core-server/src/main/java/org/glassfish/jersey/server/ApplicationHandler.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@
134134
import org.glassfish.hk2.utilities.binding.AbstractBinder;
135135
import org.glassfish.hk2.utilities.binding.ScopedBindingBuilder;
136136

137+
import org.jvnet.hk2.external.runtime.ServiceLocatorRuntimeBean;
138+
137139
import jersey.repackaged.com.google.common.base.Function;
138140
import jersey.repackaged.com.google.common.base.Predicate;
139141
import jersey.repackaged.com.google.common.collect.Collections2;
@@ -594,9 +596,22 @@ private ServerRuntime initialize(Iterable<ComponentProvider> componentProviders)
594596
.to(routingStage)
595597
.to(resourceFilteringStage)
596598
.build(Routing.matchedEndpointExtractor());
599+
597600
final ServerRuntime serverRuntime = locator.createAndInitialize(ServerRuntime.Builder.class)
598601
.build(rootStage, compositeListener, processingProviders);
599602

603+
// clear HK2 caches
604+
final ServiceLocatorRuntimeBean serviceLocatorRuntimeBean = locator.getService(ServiceLocatorRuntimeBean.class);
605+
if (serviceLocatorRuntimeBean != null) {
606+
if (LOGGER.isLoggable(Level.FINE)) {
607+
LOGGER.fine(LocalizationMessages.CLEARING_HK_2_CACHE(
608+
serviceLocatorRuntimeBean.getServiceCacheSize(),
609+
serviceLocatorRuntimeBean.getReflectionCacheSize()));
610+
}
611+
serviceLocatorRuntimeBean.clearReflectionCache();
612+
serviceLocatorRuntimeBean.clearServiceCache();
613+
}
614+
600615
// Inject instances.
601616
for (final Object instance : componentBag.getInstances(ComponentBag.EXCLUDE_META_PROVIDERS)) {
602617
locator.inject(instance);

core-server/src/main/resources/org/glassfish/jersey/server/internal/localization.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ form.param.method.error=The "@FormParam" is utilized when the request method is
130130
get.consumes.entity=A HTTP GET method, {0}, should not consume any entity.
131131
get.consumes.form.param=A HTTP GET method, {0}, should not consume any form parameter.
132132
get.returns.void=A HTTP GET method, {0}, returns a void type. It can be intentional and perfectly fine, but it is a little uncommon that GET method returns always "204 No Content".
133+
clearing.hk2.cache=Clearing Jersey HK2 caches. Service cache size: {0}, reflection cache size: {1}.
133134
chunked.output.closed=This chunked output has been closed.
134135
illegal.client.config.class.property.value="{0}" property value ({1}) does not represent a valid client configuration class. Falling back to "{2}".
135136
init.msg=Initiating Jersey application, version {0}...

0 commit comments

Comments
 (0)