From 236571eaee9383e3f3946ed2c7fdd74651dbdaea Mon Sep 17 00:00:00 2001 From: nevafuse Date: Sat, 12 Nov 2016 20:52:45 -0500 Subject: [PATCH] only periodically save recently accessed sessions Signed-off-by: nevafuse --- .../org/eclipse/jetty/server/session/HashedSession.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/session/HashedSession.java b/jetty-server/src/main/java/org/eclipse/jetty/server/session/HashedSession.java index 9a289fd08d7..e382b0eb327 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/session/HashedSession.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/session/HashedSession.java @@ -51,6 +51,12 @@ public class HashedSession extends MemSession * data stored in the session that is not serializable. */ private transient boolean _saveFailed = false; + /** + * Last time session was saved to prevent periodic saves to sessions + * that have not changed + */ + private transient long _lastSaved = 0; + /** * True if an attempt has been made to de-idle a session and it failed. Once * true, the session will not be attempted to be de-idled again. @@ -145,7 +151,7 @@ public class HashedSession extends MemSession throws Exception { File file = null; - if (!_saveFailed && _hashSessionManager._storeDir != null) + if (!_saveFailed && _hashSessionManager._storeDir != null && _lastSaved < getAccessed()) { file = new File(_hashSessionManager._storeDir, super.getId()); if (file.exists()) @@ -155,6 +161,7 @@ public class HashedSession extends MemSession try(FileOutputStream fos = new FileOutputStream(file,false)) { + _lastSaved = System.currentTimeMillis(); save(fos); } catch (Exception e)