[Java Tip] Simple Custom ThreadNamingFactory

Assign Custom Thread names is a good practice for debugging Java code as well as inferring Thread Dumps. To use custom name, we need to provide an implementation of ThreadFactory There is a simpler technique using Guava Executor executor = Executors.newFixedThreadPool(2, new ThreadFactoryBuilder().setNameFormat("Heart Beat Monitor-%d").build()); Executor executor1 = Executors.newFixedThreadPool(5, new ThreadFactoryBuilder().setNameFormat("File Watchers-%d").build()); The example shows […]

Continue reading


[Apache Curator Tip] Running Embedded Zookeeper Server

Running an Embedded Zookeeper Server for testing is a common need. Apache Curator makes it easy like a walk in the park. Pre-requisite Add following dependencies in pom.xml <dependency> <groupId>org.apache.curator</groupId> <artifactId>curator-test</artifactId> <version>2.3.0</version> </dependency> Let’s see how to start the Server public class ZkTestServers { TestingServer zkServer; public void startzkServer(int port) throws Exception { zkServer = […]

Continue reading