HashMapがデッドサイクルに陥った例

4077 ワード

// HashMap , 。
1
package com.hanzi; 2 3 import java.util.HashMap; 4 5 public class HashMapInfiniteLoop { 6 private HashMap hash = new HashMap(500); 7 8 public HashMapInfiniteLoop() { 9 Thread t1 = new Thread() { 10 public void run() { 11 for (int i = 0; i < 500000; i++) { 12 hash.put(new Integer(i), Integer.valueOf(i)); 13 } 14 System.out.println("t1 over"); 15 } 16 }; 17 Thread t2 = new Thread() { 18 public void run() { 19 for (int i = 0; i < 500000; i++) { 20 hash.put(new Integer(i),Integer.valueOf(i)); 21 } 22 System.out.println("t2 over"); 23 } 24 }; 25 t1.start(); 26 t2.start(); 27 } 28 29 public static void main(String[] args) { 30 new HashMapInfiniteLoop(); 31 } 32 }