transient variable is null after org.apache.catalina.core.StandardContext reload

461 views Asked by At

I have a variable in a class that is transient because it is not serialize, only when the tomcat is org.apache.catalina.core.StandardContext reload this same variable is null, don't know why ...

public class bean extends UnicastRemoteObject implements clientInterface{
 (...)
    private transient OAuthService service;
 (...)
}

when it appears in netbeans in Apache tomcat log org.apache.catalina.core.StandardContext reload then this variable is null ....

Can someone tell me why?

1

There are 1 answers

3
Angular University On

This can happen if the variable belongs to an object somehow attached to the HTTP session.

upon reload the contents of the session are serialized, a new classloader is created and then the session gets deserialized.

So if the variable is marked as transient it does not get serialized, and when the reload is finished it's content will be null.

See in the tomcat documentation Persistence across Restarts section for the relation between serialization and reloads, and this blog post Session persistence for some details on how tomcat handles restarts.