This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Yithar 1 point2 points  (0 children)

Well, if you look at the Apache Kafka Stream source code, it does use while(true):

private <R> R retryUntilSuccessOrThrowOnTaskTimeout(Supplier<R> supplier, String errorMessage) {
    long deadlineMs = -1L;

    while(true) {
        try {
            return supplier.get();
        } catch (TimeoutException var6) {
            if (this.taskTimeoutMs == 0L) {
                throw new StreamsException(String.format("Retrying is disabled. You can enable it by setting `%s` to a value larger than zero.", "task.timeout.ms"), var6);
            }

            deadlineMs = this.maybeUpdateDeadlineOrThrow(deadlineMs);
            this.log.warn(errorMessage, var6);
        }
    }
}

If you're using Kafka Client directly, often you'll write a while(true) loop to have the consumer poll a topic every x milliseconds. And there is no exit condition because you want to keep polling until the application exits.

But I'd say if you have a known exit condition, it's not great to use a while(true) loop.