2021年3月7日
摘要: 线程状态 thread.getState() Thread.State.TERMINATED public class TestThreadState{ public static void main(String[] args) { Thread thread = new Thread(()->{ 阅读全文
posted @ 2021-03-07 21:40 要给小八赚罐头钱 阅读(187) 评论(0) 推荐(0)
摘要: 线程强制执行 join public class TestJoin implements Runnable{ @Override public void run() { for (int i = 0; i < 100; i++) { System.out.println("靠边!俺来了!"+i); 阅读全文
posted @ 2021-03-07 16:53 要给小八赚罐头钱 阅读(14) 评论(0) 推荐(0)
摘要: 线程礼让yield 礼让不一定成功哦~ public class TestYield { public static void main(String[] args) { Yield yield = new Yield();​ new Thread(yield,"A").start(); new T 阅读全文
posted @ 2021-03-07 16:31 要给小八赚罐头钱 阅读(31) 评论(0) 推荐(0)
摘要: 模拟打印当前时间 import java.text.SimpleDateFormat;import java.util.Date;​public class TestThreadSleep implements Runnable{ private boolean flag=true; @Overri 阅读全文
posted @ 2021-03-07 16:19 要给小八赚罐头钱 阅读(69) 评论(0) 推荐(0)
摘要: 线程停止 不要用自带的stop方法,设置flag标志位停止线程。 public class TestThreadStop implements Runnable{ private boolean flag=true; @Override public void run() { int i=0; wh 阅读全文
posted @ 2021-03-07 15:34 要给小八赚罐头钱 阅读(39) 评论(0) 推荐(0)
  2021年3月6日
摘要: Lambda表达式 用于避免匿名内部类定义过多 函数式接口 任何接口,如果只包含唯一一个抽象方法,那么他就是一个函数式接口。 package com.peanutist.day08;​public class TestLamda { public static void main(String[] 阅读全文
posted @ 2021-03-06 22:54 要给小八赚罐头钱 阅读(34) 评论(0) 推荐(0)
  2021年3月5日
摘要: 静态代理 代理对象和真实对象要实现同一个接口 代理对象要代理真实角色 public class TestWedding { public static void main(String[] args) { new WeddingCompany(new Person()).wedding(); }}i 阅读全文
posted @ 2021-03-05 16:11 要给小八赚罐头钱 阅读(28) 评论(0) 推荐(0)
摘要: 龟兔赛跑 package com.peanutist.day07;​public class TestThread01 implements Runnable{ //定义一个赢家 public String winner;​ //重写run方法 public void run(){ for (int 阅读全文
posted @ 2021-03-05 14:18 要给小八赚罐头钱 阅读(54) 评论(0) 推荐(0)
  2021年3月4日
摘要: 模拟抢票 一个对象,三个进程 package com.peanutist.day06;​public class TestThread03 implements Runnable{ //有10张票 public int nums = 10; //重写run方法 public void run(){ 阅读全文
posted @ 2021-03-04 22:52 要给小八赚罐头钱 阅读(71) 评论(0) 推荐(0)
摘要: 创建线程的方法2 实现Runnable类 package com.peanutist.day06;​import org.apache.commons.io.FileUtils;​import java.io.File;import java.io.IOException;import java.n 阅读全文
posted @ 2021-03-04 17:43 要给小八赚罐头钱 阅读(112) 评论(0) 推荐(0)