@@ -32,16 +32,16 @@ public class DNSCache
3232{
3333 private static DNSCache mInstance = new DNSCache ();
3434
35- private HashMap <String , InetAddress > mCache = null ;
36- private ArrayList <String > mCachedRootDomain = null ;
35+ private final HashMap <String , InetAddress > mCache ;
36+ private final ArrayList <String > mRootDomainCache ;
3737
3838 public static DNSCache getInstance (){
3939 return mInstance ;
4040 }
4141
4242 private DNSCache () {
4343 mCache = new HashMap <>();
44- mCachedRootDomain = new ArrayList <>();
44+ mRootDomainCache = new ArrayList <>();
4545 }
4646
4747 /**
@@ -50,10 +50,12 @@ private DNSCache() {
5050 * @param hostname hostname to check
5151 * @return String the root domain or null
5252 */
53- public String getCachedRootDomain (String hostname ){
54- for (String rootDomain : mCachedRootDomain ){
55- if (hostname .endsWith (rootDomain )){
56- return rootDomain ;
53+ public String getRootDomain (String hostname ){
54+ synchronized (mRootDomainCache ) {
55+ for (String rootDomain : mRootDomainCache ) {
56+ if (hostname .endsWith (rootDomain )) {
57+ return rootDomain ;
58+ }
5759 }
5860 }
5961
@@ -66,8 +68,10 @@ public String getCachedRootDomain (String hostname){
6668 *
6769 * @param rootdomain Root domain to add to the list
6870 */
69- public void addCachedRootDomain (String rootdomain ){
70- mCachedRootDomain .add (rootdomain );
71+ public void addRootDomain (String rootdomain ){
72+ synchronized (mRootDomainCache ) {
73+ mRootDomainCache .add (rootdomain );
74+ }
7175 }
7276
7377 private InetAddress getAddress (String server ) throws IOException {
0 commit comments