Skip to content

Commit

Permalink
ATS-23
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthias Müller authored and Matthias Müller committed Apr 3, 2020
1 parent cb966e8 commit 65381ba
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/main/java/org/appng/tomcat/session/mongo/MongoStore.java
Expand Up @@ -61,6 +61,9 @@
*/
public class MongoStore extends StoreBase {

/** Name of the Tomcat Thread that cleans up sessions in the background */
private static final String TOMCAT_SESSION_THREAD = "ContainerBackgroundProcessor";

/** The currently active session for this thread */
protected ThreadLocal<Session> currentSession = new ThreadLocal<>();

Expand Down Expand Up @@ -329,7 +332,7 @@ public StandardSession load(String id) throws ClassNotFoundException, IOExceptio
session.readObjectData(ois);
session.setManager(this.manager);

if (!sticky) {
if (!(sticky || TOMCAT_SESSION_THREAD.equals(threadName))) {
BasicDBObject setHost = new BasicDBObject("$set", new BasicDBObject(HOST_PROPERTY,
String.format("%s@%s", Thread.currentThread().getName(), hostName)));
this.collection.update(sessionQuery, setHost);
Expand All @@ -352,16 +355,19 @@ public StandardSession load(String id) throws ClassNotFoundException, IOExceptio
}

private DBObject getMongoSession(String id) {

int waited = 0;
DBObject mongoSession;
BasicDBObject sessionQuery = sessionQuery(id);
if (sticky) {
String owningThread = null;
String threadName = Thread.currentThread().getName();
while (waited < maxWaitTime && (owningThread = sessionsInUse.get(id)) != null
&& !owningThread.equals(threadName)) {
info("Session %s is still used by thread %s, waiting %sms.", id, owningThread, waitTime);
waited = doWait(waited);
if (!TOMCAT_SESSION_THREAD.equals(threadName)) {
while (waited < maxWaitTime && (owningThread = sessionsInUse.get(id)) != null
&& !owningThread.equals(threadName)) {
info("Session %s is still used by thread %s, waiting %sms.", id, owningThread, waitTime);
waited = doWait(waited);
}
}
mongoSession = this.collection.findOne(sessionQuery);
} else {
Expand Down

0 comments on commit 65381ba

Please sign in to comment.