Tomcat session persistance after stop/start
I've been using intellij for years for servlet development in tomcat. But something has always been a mystery to me.
Sometimes with some combinations of Intellij/Tomcat, when I stop and then start tomcat the sessions will be serialized and deserialized so that they will still be valid. Other times over the years, this doesn't happen.
I've searched the forums and the web, and there is a lot of chatter about this and similar topics, much of it old and seemingly applying to older versions of Intellij/Tomcat. There is a lot of talk about setting 'reloadable=true' somewhere, but not clear where in server.xml, or some servlet specific xml file that may or may not exist. I'm not even sure that has anything to do with my particular problem. I'm not sure if this is tomcat or intellij or just a weird interaction of the two.
Note that I'm not talking about recompiling/redeploying, although that's currently not preserving sessions either for some reason. I'm talking about stopping tomcat, then starting it again.
This works fine for my app without Intellij. On tomcat servers the sessions persist just fine.
I'm currently running IntelliJ 9.0 Ultimate IU-93.19 and Tomcat 6.0.20.
Where's the magic switch that turns on/off session persistence?
Please sign in to leave a comment.
As far as I can see, there is no such switch. In fact, even though my Tomcat serializes sessions to hard disk on shutdown, Idea clears the base directory on startup, so Tomcat cannot restore them.
Here is how it looks like on my computer with an application that serializes a login token to the hard disk, after I shutdown Tomcat from within Idea:
The file SESSIONS.ser contains the serialized data. And here is what happens when I start Tomcat from within Idea again:
As a workaround, I copied SESSIONS.ser to a different folder, and copy the file back to its place early during Tomcat startup.
That's helpful.. perhaps as a hack I might even right something in my servet startup event to do the copy automatically.. I just have to beleive there is a straightforward way to accomplish this somehow though..
My latest mystery on this topic: My 9.0.1 install no longer shuts down tomcat when I stop the debugger. I see it call the 'catalina.bat stop' script, but then the JVM is immediately halted and non of the context shutdown events get a chance to fire.. Really really annoying. I have no idea if this is a bug, or I inadvertantly did a setting somewhere for this.
As of 9.0 (I think) there is a "Shutdown Application Server" button just under the "Stop" button. The "Stop" button kills Tomcat, whereas the "Shutdown" button shuts down cleanly.
Try adding this to either tomcat's server.mxl or in {tomcat}/conf/context.xml (see link below to see where exactly it should appear):
<Manager className="org.apache.catalina.session.PersistentManager">
<Store className="org.apache.catalina.session.FileStore" directory="YOUR_DESIRED_DIRECTORY"/>
</Manager>
This used to work for me, but hasn't recently. However, you may have better luck -- my problem might be with the application with which I'm working.
Look for PersistentManager on the tomcat docs for further details. As a matter of fact, I see there's a system property that is also required -- maybe that explains my problem.
I'd be curious if this works for you -- let me know!
~kc
** Updated **
I observe that even setting the filestore's directory, serialized sessions get removed, presumably by IDEA. If that XML snippet doesn't work for you, there's always changing tomcat startup and shutdown scripts to copy the files. See the Startup/Connection tab of your idea configuration.
That's very helpful. I click the stop button a zillion times a day but I never actually noticed the shutdown button.
But now it makes me somewhat more frustrated. The stop button is going to get hit a lot accidently, and there seems no way to modify that button bar. Worse yet, the Run dialog has no shutdown button, and the stop button seems to shutdown, so the Run/Debug dialogs are inconsistent.