【项目学习】谷粒商城学习记录6 - 异步
一、异步知识点复习
1. 四种java实现异步方法
(1) 继承Thread类,重写run()方法
- 测试
public class ThreadTest { public static void main(String[] args) { System.out.println("main...start..."); Thread01 thread01 = new Thread01(); thread01.start(); System.out.println("main...end..."); } public static class Thread01 extends Thread { @Override public void run() { System.out.println("当前线程:"+Thread.currentThread().getName()); Integer i = 10 / 2; System.out.println("运行结果:"+i); } } }
- 测试结果: