diff --git a/src/main/java/fr/abes/bestppn/kafka/TopicProducer.java b/src/main/java/fr/abes/bestppn/kafka/TopicProducer.java index 50a40ff..345be96 100644 --- a/src/main/java/fr/abes/bestppn/kafka/TopicProducer.java +++ b/src/main/java/fr/abes/bestppn/kafka/TopicProducer.java @@ -215,16 +215,10 @@ private void logEnvoi(SendResult result, ProducerRecord re record.key(), record.value(), metadata.topic(), metadata.partition(), metadata.offset(), Stream.of(result.getProducerRecord().headers().toArray()).map(h -> h.key() + ":" + Arrays.toString(h.value())).collect(Collectors.joining(";")))); } - public Integer calculatePartition(Integer nbPartitions) throws ArithmeticException { + public Integer calculatePartition(int nbPartitions) throws ArithmeticException { if (nbPartitions == 0) { throw new ArithmeticException("Nombre de threads = 0"); } - synchronized (nbPartitions) { - if (lastThreadUsed.incrementAndGet() >= nbPartitions) { - lastThreadUsed.set(0); - } - } - - return lastThreadUsed.get(); + return lastThreadUsed.getAndIncrement() % nbPartitions; } }