merlimat closed pull request #1558: Use `AtomicInteger` in LoggingFunction URL: https://github.com/apache/incubator-pulsar/pull/1558
This is a PR merged from a forked repository. As GitHub hides the original diff on merge, it is displayed below for the sake of provenance: As this is a foreign pull request (from a fork), the diff is supplied below (as it won't show otherwise due to GitHub magic): diff --git a/pulsar-functions/java-examples/src/main/java/org/apache/pulsar/functions/api/examples/LoggingFunction.java b/pulsar-functions/java-examples/src/main/java/org/apache/pulsar/functions/api/examples/LoggingFunction.java index 9cf3f550ad..e8e12aea73 100644 --- a/pulsar-functions/java-examples/src/main/java/org/apache/pulsar/functions/api/examples/LoggingFunction.java +++ b/pulsar-functions/java-examples/src/main/java/org/apache/pulsar/functions/api/examples/LoggingFunction.java @@ -18,7 +18,7 @@ */ package org.apache.pulsar.functions.api.examples; -import java.util.concurrent.atomic.AtomicIntegerFieldUpdater; +import java.util.concurrent.atomic.AtomicInteger; import org.apache.pulsar.functions.api.Context; import org.apache.pulsar.functions.api.Function; @@ -29,14 +29,13 @@ */ public class LoggingFunction implements Function<String, String> { - private static final AtomicIntegerFieldUpdater<LoggingFunction> COUNTER_UPDATER = - AtomicIntegerFieldUpdater.newUpdater(LoggingFunction.class, "counter"); + private final AtomicInteger counter = new AtomicInteger(0); @Override public String process(String input, Context context) { Logger LOG = context.getLogger(); - int counterLocal = COUNTER_UPDATER.incrementAndGet(this); + int counterLocal = counter.incrementAndGet(); if ((counterLocal & Integer.MAX_VALUE) % 100000 == 0) { LOG.info("Handled {} messages", counterLocal); } ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on 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 With regards, Apache Git Services