Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimone Bordet2015-10-30 10:16:20 +0000
committerSimone Bordet2015-10-30 10:17:28 +0000
commit45cd1f1ce628ab3b04ffed1723d543d92f7730dd (patch)
tree0a57b3ce4de037e906a14e9a79cf9f7ae4a6b119
parentb74a89bcb9d07b5538601b7798f24669a8bd4f6a (diff)
downloadorg.eclipse.jetty.project-45cd1f1ce628ab3b04ffed1723d543d92f7730dd.tar.gz
org.eclipse.jetty.project-45cd1f1ce628ab3b04ffed1723d543d92f7730dd.tar.xz
org.eclipse.jetty.project-45cd1f1ce628ab3b04ffed1723d543d92f7730dd.zip
Improved thread safety.
-rw-r--r--jetty-client/src/main/java/org/eclipse/jetty/client/DuplexConnectionPool.java36
1 files changed, 26 insertions, 10 deletions
diff --git a/jetty-client/src/main/java/org/eclipse/jetty/client/DuplexConnectionPool.java b/jetty-client/src/main/java/org/eclipse/jetty/client/DuplexConnectionPool.java
index d887923e1c..dcf74709ce 100644
--- a/jetty-client/src/main/java/org/eclipse/jetty/client/DuplexConnectionPool.java
+++ b/jetty-client/src/main/java/org/eclipse/jetty/client/DuplexConnectionPool.java
@@ -72,13 +72,29 @@ public class DuplexConnectionPool implements Closeable, Dumpable, Sweeper.Sweepa
@ManagedAttribute(value = "The number of idle connections", readonly = true)
public int getIdleConnectionCount()
{
- return idleConnections.size();
+ lock();
+ try
+ {
+ return idleConnections.size();
+ }
+ finally
+ {
+ unlock();
+ }
}
@ManagedAttribute(value = "The number of active connections", readonly = true)
public int getActiveConnectionCount()
{
- return activeConnections.size();
+ lock();
+ try
+ {
+ return activeConnections.size();
+ }
+ finally
+ {
+ unlock();
+ }
}
public Queue<Connection> getIdleConnections()
@@ -275,7 +291,7 @@ public class DuplexConnectionPool implements Closeable, Dumpable, Sweeper.Sweepa
unlock();
}
- if (activeRemoved)
+ if (activeRemoved || force)
released(connection);
boolean removed = activeRemoved || idleRemoved || force;
if (removed)
@@ -374,14 +390,14 @@ public class DuplexConnectionPool implements Closeable, Dumpable, Sweeper.Sweepa
@Override
public boolean sweep()
{
- List<Sweeper.Sweepable> toSweep = new ArrayList<>();
+ List<Connection> toSweep = new ArrayList<>();
lock();
try
{
- for (Connection connection : getActiveConnections())
+ for (Connection connection : activeConnections)
{
if (connection instanceof Sweeper.Sweepable)
- toSweep.add(((Sweeper.Sweepable)connection));
+ toSweep.add(connection);
}
}
finally
@@ -389,13 +405,13 @@ public class DuplexConnectionPool implements Closeable, Dumpable, Sweeper.Sweepa
unlock();
}
- for (Sweeper.Sweepable candidate : toSweep)
+ for (Connection connection : toSweep)
{
- if (candidate.sweep())
+ if (((Sweeper.Sweepable)connection).sweep())
{
- boolean removed = getActiveConnections().remove(candidate);
+ boolean removed = remove(connection, true);
LOG.warn("Connection swept: {}{}{} from active connections{}{}",
- candidate,
+ connection,
System.lineSeparator(),
removed ? "Removed" : "Not removed",
System.lineSeparator(),

Back to the top