Reducing code size: A common thread factory implementation
Issue #13
closed
Several parts of Babbler are using the same code again and again:
scheduledExecutorService = Executors.newSingleThreadScheduledExecutor(new ThreadFactory() {
@Override
public Thread newThread(Runnable r) {
Thread thread = new Thread(r, "...thread name...");
thread.setDaemon(true);
return thread;
}
});
It makes sense to use a common implementation, like
public static final ThreadFactory createNamedThreadFactory(final String threadName) { return new ThreadFactory() { @Override public final Thread newThread(final Runnable r) { final Thread thread = new Thread(r, threadName); thread.setDaemon(true); return thread; } } }
Less code = less memory consumption, less load time, less gc length, less possible failure modes, higher execution speed :-)
Comments (4)
-
repo owner -
repo owner - changed status to resolved
-
repo owner - changed status to closed
-
repo owner - changed version to 0.5.0
- Log in to comment
Nice proposal, I like it!
Fixed with 9b0b46d9c4d4e309bae18e32a643af53ce6df07c