I am seeing this issue and my ThreadLocal is static and final. I am using
1.5.5.
public abstract class GaeApplication extends com.vaadin.Application
implements
HttpServletRequestListener {
....
private static final ThreadLocal<GaeApplication> appReference = new
ThreadLocal<GaeApplication>();
private static GaeApplication gaep;
.....
@Override
public final void init() {
setInstance(this); // So that we immediately have access to the
current application
.....
// @return the current application instance
public static GaeApplication getInstance() {
GaeApplication app = appReference.get();
if (null == app) {
LOGGER.warning("Null threadlocal");
return gaep;
}
return appReference.get();
}
// Set the current application instance
public static void setInstance(final GaeApplication application) {
appReference.set(application);
gaep = application;
}
@Override
public void
onRequestStart(final HttpServletRequest request, final
HttpServletResponse response) {
GaeApplication.setInstance(this);
}
@Override
public void onRequestEnd(final HttpServletRequest request, final
HttpServletResponse response) {
appReference.remove();
}
My hack around this is the static variable gaep which is returned whenever
appReference.get() returns null. I am not able to boil it down to a simple
example. It possibly has something to do with a class (not the application
class) that calls GaeApplication.getInstance() being reconstituted from
serialization and checking the hashcode but am not really sure and have no
idea why that would impact ThreadLocal in any way.
Jonathan
--
You received this message because you are subscribed to the Google Groups
"Google App Engine for Java" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/google-appengine-java/-/cMrULc9FpkMJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-appengine-java?hl=en.