Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Thread-safe initialization of InstanceResolverImpl. Fixes #1511. PAYARA-1577 #1516

Merged
merged 2 commits into from
Apr 11, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
* only if the new code is made subject to such option by the copyright
* holder.
*/
// Portions Copyright [2016-2017] [Payara Foundation and/or its affiliates]

/*
* InstanceResolverImpl.java
Expand Down Expand Up @@ -66,8 +67,8 @@
public final class InstanceResolverImpl<T> extends InstanceResolver<T> {

//delegate to this InstanceResolver
private InstanceResolver<T> resolver;
private T instance;
private volatile InstanceResolver<T> resolver;
private T instance;
private final Class<T> classtobeResolved;

private WSWebServiceContext wsc;
Expand All @@ -83,17 +84,32 @@ public InstanceResolverImpl(@NotNull Class<T> clasz) {
public @NotNull T resolve(Packet request) {
//See iss 9721
//Injection and instantiation is now done lazily
if (resolver == null) {
try {
//Bug18998101. inject() call below also calls @PostConstruct method.
instance = injManager.createManagedObject(classtobeResolved, false);
} catch (InjectionException e) {
throw new WebServiceException(e);
return getResolver().resolve(request);
}

private InstanceResolver<T> getResolver() {
// proper double check to ensure single initialization
InstanceResolver<T> res = resolver;
if (res == null) {
synchronized(this) {
res = resolver;
if (res == null) {
resolver = res = initResolver();
}
}
resolver = InstanceResolver.createSingleton(instance);
getResourceInjector(endpoint).inject(wsc, instance);
}
return resolver.resolve(request);
return res;
}

private InstanceResolver<T> initResolver() {
try {
//Bug18998101. inject() call below also calls @PostConstruct method.
instance = injManager.createManagedObject(classtobeResolved, false);
} catch (InjectionException e) {
throw new WebServiceException(e);
}
getResourceInjector(endpoint).inject(wsc, instance);
return InstanceResolver.createSingleton(instance);
}

@Override
Expand Down