@@ -39,7 +39,8 @@ public final class DurableTaskGrpcWorker implements AutoCloseable {
3939 private final TaskHubSidecarServiceBlockingStub sidecarClient ;
4040 private final boolean isExecutorServiceManaged ;
4141 private volatile boolean isNormalShutdown = false ;
42-
42+ private Thread processorThread ;
43+
4344 DurableTaskGrpcWorker (DurableTaskGrpcWorkerBuilder builder ) {
4445 this .orchestrationFactories .putAll (builder .orchestrationFactories );
4546 this .activityFactories .putAll (builder .activityFactories );
@@ -70,7 +71,7 @@ public final class DurableTaskGrpcWorker implements AutoCloseable {
7071 this .workerPool = builder .executorService != null ? builder .executorService : Executors .newCachedThreadPool ();
7172 this .isExecutorServiceManaged = builder .executorService == null ;
7273 }
73-
74+
7475 /**
7576 * Establishes a gRPC connection to the sidecar and starts processing work-items in the background.
7677 * <p>
@@ -79,8 +80,10 @@ public final class DurableTaskGrpcWorker implements AutoCloseable {
7980 * continues until either a connection succeeds or the process receives an interrupt signal.
8081 */
8182 public void start () {
82- new Thread (this ::startAndBlock ).start ();
83+ this .processorThread = new Thread (this ::startAndBlock );
84+ this .processorThread .start ();
8385 }
86+
8487
8588 /**
8689 * Closes the internally managed gRPC channel and executor service, if one exists.
@@ -90,6 +93,7 @@ public void start() {
9093 */
9194 public void close () {
9295 this .isNormalShutdown = true ;
96+ this .processorThread .interrupt ();
9397 this .shutDownWorkerPool ();
9498 this .closeSideCarChannel ();
9599 }
@@ -118,7 +122,7 @@ public void startAndBlock() {
118122 logger );
119123
120124 // TODO: How do we interrupt manually?
121- while (true ) {
125+ while (true && ! this . isNormalShutdown ) {
122126 try {
123127 GetWorkItemsRequest getWorkItemsRequest = GetWorkItemsRequest .newBuilder ().build ();
124128 Iterator <WorkItem > workItemStream = this .sidecarClient .getWorkItems (getWorkItemsRequest );
0 commit comments