Skip to content

Commit

Permalink
Merge pull request payara#3048 from Cousjava/PAYARA-2931-memoryleak-p…
Browse files Browse the repository at this point in the history
…ersistenmanager

PAYARA-2931 Resolved memory leak
  • Loading branch information
Cousjava authored and Pandrex247 committed Aug 20, 2018
1 parent c47179e commit ad253e9
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Portions Copyright [2018] Payara Foundation and/or affiliates

package org.apache.catalina.session;

Expand All @@ -78,8 +79,8 @@
import java.io.ObjectOutputStream;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.ResourceBundle;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Level;
import java.util.logging.Logger;

Expand Down Expand Up @@ -140,7 +141,7 @@ public final class FileStore extends StoreBase {
* Our write-through cache of session objects
* HERCULES: addition
*/
private Hashtable<String, Session> sessions = new Hashtable<String, Session>();
private final ConcurrentHashMap<String, Session> sessions = new ConcurrentHashMap<String, Session>();


// ------------------------------------------------------------- Properties
Expand Down Expand Up @@ -346,13 +347,8 @@ public Session load(String id)
}

try {
StandardSession session =
StandardSession.deserialize(ois, manager);
session.setManager(manager);
//HERCULES: addition
// Put it in the cache
sessions.put(session.getIdInternal(), session);
//HERCULES: addition
StandardSession session = StandardSession.deserialize(ois, manager);
session.setManager(manager);
return (session);
} finally {
// Close the input stream
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Portions Copyright [2016] [Payara Foundation and/or its affiliates]
// Portions Copyright [2016-2018] [Payara Foundation and/or its affiliates]

package org.apache.catalina.session;

Expand Down Expand Up @@ -659,11 +659,20 @@ protected void processInvalidatedSessions() {
* aren't too many active sessions, or if there is no limit,
* a session is created or retrieved from the recycled pool.
*
* @return the new session
* @exception IllegalStateException if a new session cannot be
* instantiated for any reason
*/
@Override
public Session createSession() {

if (((maxActiveSessions >= 0) && (sessions.size() >= maxActiveSessions))) {
if (store == null){
//too many active sessions and no store
throw new IllegalStateException(rb.getString(LogFacade.CREATE_SESSION_EXCEPTION));
}
//swap out active sessions to store
processMaxActiveSwaps();
}
return (super.createSession());

}
Expand All @@ -686,8 +695,16 @@ public Session createSession() {
* @return the new session, or <code>null</code> if a session with the
* requested id already exists
*/
@Override
public Session createSession(String sessionId) {

if (((maxActiveSessions >= 0) && (sessions.size() >= maxActiveSessions))) {
if (store == null){
//too many active sessions and no store
throw new IllegalStateException(rb.getString(LogFacade.CREATE_SESSION_EXCEPTION));
}
//swap out active sessions to store
processMaxActiveSwaps();
}
return (super.createSession(sessionId));

}
Expand Down Expand Up @@ -1336,11 +1353,11 @@ protected void processMaxActiveSwaps() {
Session sessions[] = findSessions();

// FIXME: Smarter algorithm (LRU)
if (getMaxActiveSessions() > sessions.length)
if (getMaxActiveSessions() >= sessions.length)
return;

if(log.isLoggable(Level.FINE)) {
log.log(Level.FINE, LogFacade.TOO_MANY_ACTIVE_SESSION, Integer.valueOf(sessions.length));
log.log(Level.FINE, LogFacade.TOO_MANY_ACTIVE_SESSION, sessions.length);
}
int toswap = sessions.length - getMaxActiveSessions();
long timeNow = System.currentTimeMillis();
Expand Down

0 comments on commit ad253e9

Please sign in to comment.