Fix creating new worker pool for each inbound request
@@ -36,6 +36,8 @@ import org.wso2.carbon.inbound.endpoint.protocol.http.management.HTTPEndpointMan
import java.io.IOException;
import java.io.OutputStream;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReentrantLock;
import java.util.regex.Pattern;
import static org.wso2.carbon.inbound.endpoint.common.Constants.SUPER_TENANT_DOMAIN_NAME;
@@ -50,6 +52,7 @@ public class InboundHttpSourceHandler extends SourceHandler {
private final SourceConfiguration sourceConfiguration;
private int port;
private WorkerPool workerPool;
+ private Lock lock = new ReentrantLock();
public InboundHttpSourceHandler(int port, SourceConfiguration sourceConfiguration) {
super(sourceConfiguration);
@@ -81,14 +84,16 @@ public class InboundHttpSourceHandler extends SourceHandler {
Pattern dispatchPattern = null;
// Need to initialize workerPool only once
+ if (workerPool == null) {
+ lock.lock();
+ try {
if (workerPool == null) {
WorkerPoolConfiguration workerPoolConfiguration = HTTPEndpointManager.getInstance()
.getWorkerPoolConfiguration(SUPER_TENANT_DOMAIN_NAME, port);
if (workerPoolConfiguration != null) {
workerPool = sourceConfiguration.getWorkerPool(workerPoolConfiguration.getWorkerPoolCoreSize(),
workerPoolConfiguration.getWorkerPoolSizeMax(),
- workerPoolConfiguration
- .getWorkerPoolThreadKeepAliveSec(),
+ workerPoolConfiguration.getWorkerPoolThreadKeepAliveSec(),
workerPoolConfiguration.getWorkerPoolQueuLength(),
workerPoolConfiguration.getThreadGroupID(),
workerPoolConfiguration.getThreadID());
@@ -96,6 +101,10 @@ public class InboundHttpSourceHandler extends SourceHandler {
workerPool = sourceConfiguration.getWorkerPool();
}
}
+ } finally {
+ lock.unlock();
+ }
+ }
Object correlationId = conn.getContext().getAttribute(CorrelationConstants.CORRELATION_ID);
if (correlationId != null) {
