Пример #1
0
 /// <summary>
 /// Try to add a value to the map.
 /// </summary>
 internal T Add(string key, T value)
 {
     while (true)
     {
         var newEntry = new SoftReference <T>(value);
         var entry    = map.PutIfAbsent(key, newEntry);
         if (entry != null)
         {
             // There was an entry in the map.
             var result = entry.Get();
             if (result != null)
             {
                 // The entry holds a valid reference, we're done
                 return(result);
             }
             else
             {
                 // The entry has been cleared
                 map.Replace(key, newEntry);
             }
         }
     }
 }
Пример #2
0
 public void TestReplaceValue3_NullReferenceException()
 {
     try
     {
         ConcurrentHashMap<Object, Object> c = new ConcurrentHashMap<Object, Object>(5);
         c.Replace("whatever", one, null);
         ShouldThrow();
     }
     catch(NullReferenceException)
     {
     }
 }