ableegoldman commented on a change in pull request #9273:
URL: https://github.com/apache/kafka/pull/9273#discussion_r501868835



##########
File path: streams/src/main/java/org/apache/kafka/streams/KafkaStreams.java
##########
@@ -364,6 +370,73 @@ public void setUncaughtExceptionHandler(final 
Thread.UncaughtExceptionHandler eh
         }
     }
 
+    /**
+     * Set the handler invoked when a {@link 
StreamsConfig#NUM_STREAM_THREADS_CONFIG internal thread}
+     * throws an unexpected exception.
+     * These might be exceptions indicating rare bugs in Kafka Streams, or they
+     * might be exceptions thrown by your code, for example a 
NullPointerException thrown from your processor
+     * logic.
+     * <p>
+     * Note, this handler must be threadsafe, since it will be shared among 
all threads, and invoked from any
+     * thread that encounters such an exception.
+     *
+     * @param streamsUncaughtExceptionHandler the uncaught exception handler 
of type {@link StreamsUncaughtExceptionHandler} for all internal threads; 
{@code null} deletes the current handler
+     * @throws IllegalStateException if this {@code KafkaStreams} instance is 
not in state {@link State#CREATED CREATED}.
+     */
+    public void setUncaughtExceptionHandler(final 
StreamsUncaughtExceptionHandler streamsUncaughtExceptionHandler) {
+        final StreamsUncaughtExceptionHandler handler = throwable -> 
handleStreamsUncaughtException(throwable, streamsUncaughtExceptionHandler);
+        synchronized (stateLock) {
+            if (state == State.CREATED) {
+                for (final StreamThread thread : threads) {

Review comment:
        I think users may find at least some of the same functionality to be 
useful, in particular the "shutdown client" and "shutdown application" enums. I 
also feel like users may want to be able to restart the global thread.  I think 
we can consider that out of scope for now, but I'd prefer to avoid introducing 
a new method that just accepts the old kind of uncaught exception handler if 
we're just going to deprecate that too.
   
   But I do agree that it's pretty different, and we also don't want to commit 
to adding this functionality for the global thread right away so we should make 
sure it's clear what is and isn't implemented. So what do you think about 
mirroring the new handler for the StreamThread, eg adding a 
"GlobalUncaughtExceptionHandler", and just only including the `SHUTDOWN_THREAD` 
enum in the initial version? That way we're set up to easily extend the global 
handling feature without necessarily needing to implement it right away




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to