Reputation: 21
I am having a strange issue when using PersistentManager with JDBC Store on Tomcat6. I can see the session being written into the database. I am able to put things like int, boolean, String, and Date directly into the session, but when I put in a custom java object, the session gets deleted from the database after a few seconds. The custom object implements the Serializable interface.
File: context.xml
<Manager className="org.apache.catalina.session.PersistentManager"
saveOnRestart="true"
debug="10"
checkInterval="0"
maxActiveSessions="-1"
minIdleSwap="-1"
maxIdleSwap="0"
maxIdleBackup="0"
maxInactiveInterval="600">
<Store className="org.apache.catalina.session.JDBCStore"
connectionURL="[CONNECTION URL]"
driverName="com.mysql.jdbc.Driver"
sessionAppCol="app_name"
sessionDataCol="session_data"
sessionIdCol="session_id"
sessionLastAccessedCol="last_access"
sessionMaxInactiveCol="max_inactive"
sessionTable="sessions"
sessionValidCol="valid_session"
checkInterval="0"
debug="99" />
</Manager>
<Valve className="org.apache.catalina.valves.PersistentValve" />
File: TestObj.java
import java.io.Serializable;
public class TestObj implements Serializable {
private static final long serialVersionUID = 1L;
private String test;
private Integer testObjId;
public String getTest() {
return test;
}
public void setTest(String test) {
this.test = test;
}
public Integer getTestObjId() {
return testObjId;
}
public void setTestObjId(Integer testObjId) {
this.testObjId = testObjId;
}
@Override
public String toString() {
StringBuffer str = new StringBuffer();
str.append("[");
str.append("test : ").append(test);
str.append(", testObjId : ").append(testObjId);
str.append("]");
return str.toString();
}
public TestObj() {
this.test = "";
this.testObjId = 0;
}
}
Note: I have tried only including either an integer or String in the TestObj and the session is still removed prematurely.
I also implemented listeners using the HttpSessionListener and HttpSessionAttributeListener interfaces to see when sessions are created and when session attributes change. I never see a message that the session or session attributes are destroyed.
I suspect its the PersistentManager cleaning up sessions. I checked the timestamps and the sessions that are removed have not be idle for more than 10 minutes as specified in maxInactiveInterval in my context.xml file.
Any insight and help would be greatly appreciated! Thanks!
Upvotes: 1
Views: 1617
Reputation: 21
I think I found the root cause for this issue. I looked through the MySQL logs and I see 2 connections to the database. One of the connections always sent DELETE statements that deleted the sessions in question. The other sent both DELETE and INSERT statements which is normal when sessions are updated according to the source code for org.apache.catalina.session.JDBCStore.
I realized that I compiled and accidentally deployed the application on my local machine with the same configurations before this all started happening. The persistence manager on both the server and on my machine seems to check the database for expired sessions. It didn't recognize the sessions from the server and just deleted them.
Basically, don't use the PersistentManager on the same application that are running on different machines that aren't part of the same cluster.
@Will, thanks for you suggestions!
Upvotes: 1