摘要:
线程池 ExecutorService 和Executors public class TestPool { public static void main(String[] args) { //创建服务 //newFixedThreadPool 参数为:线程池大小 ExecutorService 阅读全文
posted @ 2023-04-03 21:21
越狱兔狲
阅读(25)
评论(0)
推荐(0)
摘要:
Lock锁 ReentrantLock lock=new ReentrantLock(); class TestLock2 implements Runnable{ int ticketName=10; //定义lock锁 private final ReentrantLock lock=new R 阅读全文
posted @ 2023-04-03 21:20
越狱兔狲
阅读(25)
评论(0)
推荐(0)
摘要:
三大不安全线程 //模拟不安全的买票public class TestBuyTicket { public static void main(String[] args) { maiPiao maiPiao=new maiPiao(); new Thread(maiPiao,"小明").start 阅读全文
posted @ 2023-04-03 21:18
越狱兔狲
阅读(64)
评论(0)
推荐(0)
摘要:
Join //join线程强制执行(插队)public class TestJoin implements Runnable{ @Override public void run() { for (int i = 0; i < 100; i++) { System.out.println("我是v 阅读全文
posted @ 2023-04-03 21:17
越狱兔狲
阅读(16)
评论(0)
推荐(0)
摘要:
Lambda new Thread(()->System.out.println("多线程学习....")).start; /** 避免匿名内部类定义过多* 可以让你的代码看起来整洁* 去掉了一些没有意义代码,只留下核心代码** *///lambda简化代码过程public class TestLa 阅读全文
posted @ 2023-04-03 21:16
越狱兔狲
阅读(87)
评论(0)
推荐(0)
摘要:
Thread //继承Thread类,重写run方法,调用start开启线程//注意:线程开启不一定立即执行,由CPU调度执行public class Demo01 extends Thread{// public void run(){ for (int i = 0; i < 20; i++) { 阅读全文
posted @ 2023-04-03 21:15
越狱兔狲
阅读(76)
评论(0)
推荐(0)
浙公网安备 33010602011771号