一、创建线程
1 package com.eamon.thread;
2
3 /**
4 * 創(chuàng)建線程的兩種方式
5 *
6 * @author Eamon
7 *
8 */
9 public class CreateThread {
10
11 public static void main(String[] args) {
12 // 第一種 繼承Thread類
13 Thread thread1 = new Thread(new MyThread1());
14 thread1.start();
15 // 第二種 實(shí)現(xiàn)Runable接口
16 Thread thread2 = new Thread(new MyThread2());
17 thread2.start();
18
19 //Thread 中 run() 方法源碼
20 /*@Override
21 public void run() {
22 if (target != null) {
23 target.run();
24 }
25 }*/
26 }
27 }
28 class MyThread1 extends Thread{
29 @Override
30 public void run() {
31 System.out.println("hello thread1....");
32 }
33 }
34 class MyThread2 implements Runnable{
35 @Override
36 public void run() {
37 System.out.println("hello thread2....");
38 }
39 }
運(yùn)行結(jié)果:
hello thread1.... hello thread2....?
轉(zhuǎn)載于:https://www.cnblogs.com/zhangeamon/p/4149778.html
總結(jié)
- 上一篇: 操作iframe里面的标签内容
- 下一篇: iOS通知机制