Merge pull request #5109 from eclipse/jetty-9.4.x-5108-SessionTrackerScalability

Issue #5108 - improve scalability of WebSocket SessionTrackers
This commit is contained in:
Lachlan 2020-08-04 20:28:28 +10:00 committed by GitHub
commit 8af767f3a6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 8 deletions

View File

@ -19,19 +19,21 @@
package org.eclipse.jetty.websocket.jsr356;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArraySet;
import java.util.concurrent.ConcurrentHashMap;
import javax.websocket.Session;
import org.eclipse.jetty.util.component.AbstractLifeCycle;
import org.eclipse.jetty.util.component.LifeCycle;
public class JsrSessionTracker extends AbstractLifeCycle implements JsrSessionListener
{
private CopyOnWriteArraySet<JsrSession> sessions = new CopyOnWriteArraySet<>();
private final Set<JsrSession> sessions = Collections.newSetFromMap(new ConcurrentHashMap<>());
public Set<javax.websocket.Session> getSessions()
public Set<Session> getSessions()
{
return Collections.unmodifiableSet(sessions);
return Collections.unmodifiableSet(new HashSet<>(sessions));
}
@Override
@ -49,7 +51,7 @@ public class JsrSessionTracker extends AbstractLifeCycle implements JsrSessionLi
@Override
protected void doStop() throws Exception
{
for (JsrSession session : sessions)
for (Session session : sessions)
{
LifeCycle.stop(session);
}

View File

@ -20,8 +20,9 @@ package org.eclipse.jetty.websocket.common;
import java.io.IOException;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArraySet;
import java.util.concurrent.ConcurrentHashMap;
import org.eclipse.jetty.util.component.AbstractLifeCycle;
import org.eclipse.jetty.util.component.Dumpable;
@ -29,11 +30,11 @@ import org.eclipse.jetty.util.component.LifeCycle;
public class SessionTracker extends AbstractLifeCycle implements WebSocketSessionListener, Dumpable
{
private CopyOnWriteArraySet<WebSocketSession> sessions = new CopyOnWriteArraySet<>();
private final Set<WebSocketSession> sessions = Collections.newSetFromMap(new ConcurrentHashMap<>());
public Set<WebSocketSession> getSessions()
{
return Collections.unmodifiableSet(sessions);
return Collections.unmodifiableSet(new HashSet<>(sessions));
}
@Override