Code example for ThreadFactoryBuilder

0
public class KafkaRetentionPartitioner { 
    private static DynamicLongProperty retention = new DynamicLongProperty(
            "kafka.producer.partition.retention", 1000); 
 
    private final ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor(
            new ThreadFactoryBuilder().setDaemon(false).setNameFormat("KafkaRetentionPartitioner-%d").build());
    private final AtomicLong hash = new AtomicLong(new Random().nextInt((int) retention.get()));
 
    public KafkaRetentionPartitioner() { 
        scheduler.scheduleAtFixedRate(new Runnable() {
 
            @Override 
            public void run() { 
                hash.incrementAndGet();
            } 
        }, retention.get(), retention.get(), TimeUnit.MILLISECONDS);
    } 
 
    public long getKey() { 
        return hash.get();
Connect your IDE to all the code out there  Get Codota for Java