随笔分类 - Java线程
摘要:Lock锁 可重入锁:ReentrantLock类 public class LockTest { public static void main(String[] args) { Test a = new Test("小红"); new Thread(a).start(); new Thread(
阅读全文
摘要:缓冲区法 生产者 消费者 产品 容器 public class TestTwo { // 生产者 消费者 容器 产品 public static void main(String[] args) { Home home = new Home(); new Thread(new Productor(h
阅读全文
摘要:并发 解决办法:队列 + 锁 线程不安全示例(操作同一个对象) public static void main(String[] args) { BuyTicket buyTicket = new BuyTicket(); // BuyTicket buyTicket1 = new BuyTicke
阅读全文
摘要:守护线程、用户线程 线程默认的都是用户线程,我们需要设置thread.setDaemon(true)来改为守护线程; 守护线程,虚拟机不会监测它,等别的线程都跑完了,守护线程会自动停止; public static void main(String[] args) { Teacher teacher
阅读全文
摘要:继承Thread类 public class TestThread extends Thread{ private String url; private String name; public TestThread(String url,String name){ this.url = url;
阅读全文