###25.01_多執行緒(單例設計模式)(掌握)
單例寫法兩種:
###25.02_多執行緒(runtime類)
###25.03_多執行緒(timer)(掌握)
###25.04_多執行緒(兩個執行緒間的通訊)(掌握)
2.怎麼通訊
###25.05_多執行緒(三個或三個以上間的執行緒通訊)
1.同步
2.通訊
###25.07_多執行緒(執行緒組的概述和使用)(了解)
我們也可以給執行緒設定分組
b:案例演示
myrunnable mr = new myrunnable();
thread t1 = new thread(mr, "張三");
thread t2 = new thread(mr, "李四");
//獲取執行緒組
// 執行緒類裡面的方法:public final threadgroup getthreadgroup()
threadgroup tg1 = t1.getthreadgroup();
threadgroup tg2 = t2.getthreadgroup();
// 執行緒組裡面的方法:public final string getname()
string name1 = tg1.getname();
string name2 = tg2.getname();
system.out.println(name1);
system.out.println(name2);
// 通過結果我們知道了:執行緒預設情況下屬於main執行緒組
// 通過下面的測試,你應該能夠看到,默任情況下,所有的執行緒都屬於同乙個組
system.out.println(thread.currentthread().getthreadgroup().getname());
// threadgroup(string name)
threadgroup tg = new threadgroup("這是乙個新的組");
myrunnable mr = new myrunnable();
// thread(threadgroup group, runnable target, string name)
thread t1 = new thread(tg, mr, "張三");
thread t2 = new thread(tg, mr, "李四");
system.out.println(t1.getthreadgroup().getname());
system.out.println(t2.getthreadgroup().getname());
//通過組名稱設定後台執行緒,表示該組的執行緒都是後台執行緒
tg.setdaemon(true);
###25.08_多執行緒(執行緒的五種狀態)(掌握)
###25.09_多執行緒(執行緒池的概述和使用)(了解)
b:內建執行緒池的使用概述
使用步驟:
c:案例演示
// public static executorservice newfixedthreadpool(int nthreads)
executorservice pool = executors.newfixedthreadpool(2);
// 可以執行runnable物件或者callable物件代表的執行緒
pool.submit(new myrunnable());
pool.submit(new myrunnable());
//結束執行緒池
pool.shutdown();
###25.10_多執行緒(多執行緒程式實現的方式3)(了解)
弊端:
###25.11_設計模式(簡單工廠模式概述和使用)(了解)
b:優點
c:缺點
d:案例演示
public class animalfactory
//public static dog createdog()
//public static cat createcat()
//改進
public static animal createanimal(string animalname)
else if(「cat」.equals(animale)) else
}}
###25.12_設計模式(工廠方法模式的概述和使用)(了解)
b:優點
c:缺點
d:案例演示
動物抽象類:public abstract animal
工廠介面:public inte***ce factory
具體狗類:public class dog extends animal {}
具體貓類:public class cat extends animal {}
開始,在測試類中每個具體的內容自己建立物件,但是,建立物件的工作如果比較麻煩,就需要有人專門做這個事情,所以就知道了乙個專門的類來建立物件。發現每次修改**太麻煩,用工廠方法改進,針對每乙個具體的實現提供乙個具體工廠。
狗工廠:public class dogfactory implements factory
}貓工廠:public class catfactory implements factory
}
###25.13_gui(如何建立乙個視窗並顯示)
###25.14_gui(布局管理器)
borderlayout(邊界布局管理器)
gridlayout(網格布局管理器)
cardlayout(卡片布局管理器)
gridbaglayout(網格包布局管理器)
###25.16_gui(滑鼠監聽)
###25.17_gui(鍵盤監聽和鍵盤事件)
###25.18_gui(動作監聽)
###25.19_設計模式(介面卡設計模式)(掌握)
b.介面卡原理
事件處理
day25 多執行緒
單例寫法兩種 2.怎麼通訊 3.sleep方法和wait方法的區別?2.通訊 我們也可以給執行緒設定分組 b 案例演示 myrunnable mr new myrunnable thread t1 new thread mr,張三 thread t2 new thread mr,李四 獲取執行緒組 ...
每日演算法 day 25
那些你早出晚歸付出的刻苦努力,你不想訓練,當你覺的太累了但還是要咬牙堅持的時候,那就是在追逐夢想,不要在意終點有什麼,要享受路途的過程,或許你不能成就夢想,但一定會有更偉大的事情隨之而來。mamba out 2020.3.10 貪心問題注意策略得轉化 別要死於固定得暴力形式,雖然是貪心思想實現起來也...
python學習歷程day25
今天學習了 1.反射 getattr 物件,字串 在物件中找字串 hasattr 物件,字串 判斷字串是否出現在物件中 setattr 物件,字串 在物件中新增字串 delattr 物件,字串 在物件中刪除字串 物件 包括模組,類,函式,方法,變數 字串 包括類,函式,方法,變數 isinstanc...