I have a logging solution that writes down the hashes of messages. I consider some of these hashes to be safe and I want to skip logging those. I have implemented a whitelist that is a directory containing whitelisted hashes. There is a timer task that updates that list every 10 minutes.
I have tried testing it from multiple angles, but experience shows that it is near to impossible to generate the load with the diversity that I see in the wild. So could someone point out any shortcomings in my approach, only relevant parts showed:
public class MyLogger {
private volatile AtomicReference<List<String>> whitelist = new AtomicReference<List<String>>();
private void startWhitelistListener() {
new Timer().scheduleAtFixedRate(
new TimerTask() {
@Override
public void run() {
updateWhitelist();
}
}, 1000, 60 * 10 * 1000
);
}
private void updateWhitelist() {
try{
ArrayList<String> tempList = new ArrayList<String>();
for (File f : scriptWhitelistDirectory.listFiles()){
tempList.add(f.getName());
}
whitelist.set(tempList);
} catch (Throwable ignore){}
}
....
}
Now there will be threads accessing the whitelist like:
if (whitelist.get().contains(hash)) return null;
Is the implementation thread safe?