1. 代码

    	import java.util.ArrayList;
    
    	/**
    	 * description:
    	 *
    	 * @author: dawn.he QQ:       905845006
    	 * @email: [email protected]
    	 * @email: [email protected]
    	 * @date: 2019/10/6    1:15 AM
    	 */
    	public class UnsafeArrayList {
    		static ArrayList al = new ArrayList();
    
    		static class AddTask implements Runnable {
    			@Override
    			public void run() {
    
    				try {
    					Thread.sleep(100);
    
    				} catch (
    						InterruptedException e)
    
    				{
    				}
    
    				for (int i = 0; i < 1000000; i++) al.add(new Object());
    			}
    
    		}
    
    		public static void main(String[] args) throws InterruptedException {
    			Thread t1 = new Thread(new AddTask(), "t1");
    			Thread t2 = new Thread(new AddTask(), "t2");
    			t1.start();
    			t2.start();
    			Thread t3 = new Thread(new Runnable() {
    				@Override
    				public void run() {
    					while (true) {
    						try {
    							Thread.sleep(1000);
    						} catch (
    								InterruptedException e)
    
    						{
    						}
    					}
    
    				}
    			}, "t3");
    			t3.start();
    		}
    	}
    

    断点

    idea 多线程调试-LMLPHP

    设置条件(!Thread.currentThread().getName().equals("main"))idea 多线程调试-LMLPHP

10-06 03:24