when programming for a thread safe project, how to determine which field should be thread safe. for example we have a class in a project called TestThreadSafe in a multithread project.
public class TestThreadSafe {
public AtomicLong pCounter = new AtomicLong();
public AtomicLong mCounter = new AtomicLong();
protected final ConcurrentMap<K, V> Map = new ConcurrentHashMap<K, V>();
private ScheduledExecutorService ses;
private String dir;
}
Here, why do not define ses and dir as final or volatile fields?