黄色网址大全免费-黄色网址你懂得-黄色网址你懂的-黄色网址有那些-免费超爽视频-免费大片黄国产在线观看

Java面向對象
Java異常
Java數組
Java常用類
Java集合
Java IO流
Java線程
Java反射
Socket編程
Java注解開發
Java GoF設計模式
HashMap
Java內存模型
Java線性表

Java線程基礎操作

線程的常用操作

static int

activeCount() 返回活動線程數量

static Thread

currentThread() 返回當前線程

ClassLoader

getContextClassLoader() 返回類加載器

long

getId() 返回線程的id,每個線程都有唯一 的id

String

getName() 返回線程名稱.

int

getPriority() 返回線程優先級

Thread.State

getState() 返回線程狀態

void

interrupt() 中斷線程.

static boolean

interrupted() 判斷線程的中斷狀態

boolean

isAlive() 判斷線程是否終止

boolean

isDaemon() 是否為守護線程

boolean

isInterrupted() 判斷線程的中斷狀態

void

join() 線程合并

void

run() 

void

setDaemon(boolean on) 設置線程為守護線程

void

setName(String name) 設置線程名稱

void

setPriority(int newPriority) 設置優先級

static void

sleep(long millis)線程睡眠(休眠)

void

start() 開啟新的線程

void

stop() 線程終止

String

toString() 

static void

yield() 線程讓步

package com.wkcto.chapter07.method;
/**
 * 演示線程的基本操作
 * 			Thread.currentThread()		返回當前線程
 * 			t1.getName()					返回線程名稱, 線程默認名稱 : Thread-0 / Thread-1 
 * 			t1.setName("t1")				設置線程名稱
 * 			t1.isAlive()					判斷線程是否終止
 * 			Thread.activeCount()			活動線程的數量
 * @author 蛙課網
 *
 */
public class Test01 {
	public static void main(String[] args) {
		Thread t1 = new Thread( new Runnable() {
			@Override
			public void run() {
				for( int i = 1; i<=100; i++){
//					System.out.println("sub thread: " + i);
					System.out.println( Thread.currentThread().getName() + "==>" + i);
				}
			}
		});	
		t1.setName("t1");
		t1.start();
		
		new Thread( new Runnable() {
			@Override
			public void run() {
				for( int i = 1; i<=100; i++){
					System.out.println( Thread.currentThread().getName() + "====>" + i);
				}
			}
		},  "t2").start();
		
		System.out.println("11 : " +  Thread.activeCount() );  		//活動線程的數量
		
		//main線程
		for( int i = 1; i<=100; i++){
			System.out.println( Thread.currentThread().getName() + "------->" + i);
		}
		
		System.out.println( "t1 alive: " + t1.isAlive());
		
		System.out.println("22 : " +  Thread.activeCount() );  		//活動線程的數量
	}
}
package com.wkcto.chapter07.method;
/**
 * 守護線程
 * 		為其他線程服務的, 不能單獨運行 , 當JVM中只有守護線程時, JVM退出 
 * @author 蛙課網
 *
 */
public class Test02 {

	public static void main(String[] args) {
		Thread t1 = new Thread(new Runnable() {
			@Override
			public void run() {
				for (int i = 1; i <= 100; i++) {
					System.out.println(Thread.currentThread().getName() + "--> " + i);
				}
			}
		} , "t1");
		t1.start();
		
		Thread t2 = new Thread(new Runnable() {
			@Override
			public void run() {
				for (int i = 1; i <= 500; i++) {
					System.out.println(Thread.currentThread().getName() + "----> " + i);
				}
			}
		} , "t2");
		t2.setDaemon( true ); 		//設置線程為守護線程
		t2.start();
		
		//main線程
		for (int i = 1; i <= 100; i++) {
			System.out.println(Thread.currentThread().getName() + "==> " + i);
		}
	}

}
package com.wkcto.chapter07.method;
/**
 * 判斷線程的狀態
 * @author 蛙課網
 *
 */
public class Test03 {

	public static void main(String[] args) {
		Thread t1 = new Thread(new Runnable() {
			@Override
			public void run() {
				for (int i = 1; i <= 100; i++) {
					System.out.println(Thread.currentThread().getName() + "--> " + i);
				}
			}
		});
		
		System.out.println("111: " + t1.getState());	 //111: NEW 新建狀態,剛剛創建了線程對象	
		t1.start();
		System.out.println("222: " + t1.getState());	//222: RUNNABLE 可運行狀態,就緒狀態, 調用了start()
		
		//main線程
		for (int i = 1; i <= 300; i++) {
			System.out.println(Thread.currentThread().getName() + "--> " + i);
		}
		
		System.out.println("333: " + t1.getState()); 	//333: TERMINATED 終止狀態,線程已結束	
		
	}

}

線程的生命周期

全部教程
主站蜘蛛池模板: 欧美精品导航 | 全黄性| 色青五月天 | 黄色影片在线免费观看 | 免费理伦 | 福利视频一区 | 一级毛片在线看 | 亚洲视频aaa| 亚洲国产日产韩国欧美综合 | 91大片淫黄大片.在线天堂 | 成人合集大片bd高清在线观看 | 丝袜综合网 | www.黄色网址 | 日韩欧美一区二区在线 | 日韩久久精品视频 | 久久精品国产精品亚洲精品 | 日本黄大片在线观看 | 最色网站入口 | 动漫涩涩视频 | 成年人免费毛片 | 日日干天天爽 | 麻豆一区区三三四区产品麻豆 | 免费的一级片 | 最好看免费中文字幕2019 | 欧美精品白嫩bbwbbwbbw | 日韩国产欧美成人一区二区影院 | 成年激情网 | 欧美一区二区在线观看免费网站 | 男人边吃奶边爱边做视频刺激 | 男女免费观看视频 | 欧美日韩麻豆 | 日韩成人在线影院 | 欧美性xxx免费看片 欧美性导航 | 本道久久综合88全国最大色 | 天天躁夜夜躁狠狠躁2021西西 | 一级做a爱过程免费观看 | 久久精品天天中文字幕人 | 西西人体大胆77777视频 | 三级黄色片免费观看 | 国产精品一在线观看 | 亚洲一区二区三区久久久久 |