public class JvmThread { public static void main(String[] args) { new Thread(() -> { List<byte[]> list = new ArrayList<byte[]>(); while (true) { System.out.println(new Date().toString() Thread.currentThread() "=="); byte[] b = new byte[1024 * 1024 * 1]; list.add(b); try { Thread.sleep(1000); } catch (Exception e) { e.printStackTrace(); } } }).start(); // 线程二 new Thread(() -> { while (true) { System.out.println(new Date().toString() Thread.currentThread() "=="); try { Thread.sleep(1000); } catch (Exception e) { e.printStackTrace(); } } }).start(); } }
Wed Nov 07 14:42:18 CST 2018Thread[Thread-1,5,main]== Wed Nov 07 14:42:18 CST 2018Thread[Thread-0,5,main]== Wed Nov 07 14:42:19 CST 2018Thread[Thread-1,5,main]== Wed Nov 07 14:42:19 CST 2018Thread[Thread-0,5,main]== Exception in thread "Thread-0" java.lang.OutOfMemoryError: Java heap space at com.gosaint.util.JvmThread.lambda$main$0(JvmThread.java:21) at com.gosaint.util.JvmThread$$Lambda$1/521645586.run(Unknown Source) at java.lang.Thread.run(Thread.java:748) Wed Nov 07 14:42:20 CST 2018Thread[Thread-1,5,main]== Wed Nov 07 14:42:21 CST 2018Thread[Thread-1,5,main]== Wed Nov 07 14:42:22 CST 2018Thread[Thread-1,5,main]==
END 十期推荐 【251期】面试官:谈谈你对零拷贝的理解~ 【252期】运行时常量池的一道面试题(JDK8环境) 【253期】面试官:熟悉Docker操作吗?说几个常用的Docker命令吧 【254期】面试官:来谈谈微服务组件Feign的工作原理吧 【255期】面试官:Mybatis是如何运用设计模式的? 【256期】面试官常考的 21 条 Linux 命令 【257期】面试官:谈谈你对Java线程安全与不安全的理解 【258期】今日头条的面试题:LRU原理和Redis实现 【259期】面试官:Spring事务失效的场景有哪些?如何解决? 【260期】Java线程池,这篇能让你和面试官聊了半小时 ? ~