Skip to content

Commit

Permalink
Merge pull request #40 from senthuran16/handle-rejected-execution-exc…
Browse files Browse the repository at this point in the history
…eption-new-master

Handle rejected executions in a blocking manner
  • Loading branch information
senthuran16 authored Sep 1, 2023
2 parents 2ffae05 + cd18dde commit c28cf00
Showing 1 changed file with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
import java.util.UUID;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.RejectedExecutionHandler;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.ReentrantLock;
Expand Down Expand Up @@ -85,9 +86,22 @@ public GenericServiceServer(GrpcServerConfigs grpcServerConfigs, AbstractGrpcSou
this.requestClass = requestClass;
super.lock = new ReentrantLock();
super.condition = lock.newCondition();
this.executorService = new ThreadPoolExecutor(grpcServerConfigs.getThreadPoolSize(),
ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(grpcServerConfigs.getThreadPoolSize(),
grpcServerConfigs.getThreadPoolSize(), 0L, TimeUnit.MILLISECONDS,
new LinkedBlockingQueue<>(grpcServerConfigs.getThreadPoolBufferSize()));

threadPoolExecutor.setRejectedExecutionHandler(new RejectedExecutionHandler() {
@Override
public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
try {
executor.getQueue().put(r);
} catch (InterruptedException e) {
throw new SiddhiAppRuntimeException(siddhiAppName + ": " + streamID + ": " + e.getMessage(), e);
}
}
});
this.executorService = threadPoolExecutor;

setServerPropertiesToBuilder(siddhiAppName, streamID);
addServicesAndBuildServer(siddhiAppName, streamID);
}
Expand Down

0 comments on commit c28cf00

Please sign in to comment.