I\'ve created a pool of 4 worker threads to process some files. In the test there\'s about 200 of them. The thread pool version is already about 3 times faster than doing it
Extend ThreadLocal
for your class and override the initialValue()
method. By default, it returns null.
private static class ThreadLocalGenerateSHA1 extends
ThreadLocal {
@Override
protected GenerateSHA1 initialValue() {
return new GenerateSHA1();
}
}
private static final ThreadLocalGenerateSHA1 generateSHA1 = new ThreadLocalGenerateSHA1();
...
On the tasks, simply call the get()
method of generateSHA1. You do not need to call set()
.