day25 多執行緒

2021-07-26 11:00:17 字數 2382 閱讀 7167

單例寫法兩種:

2.怎麼通訊

3.sleep方法和wait方法的區別?

2.通訊

我們也可以給執行緒設定分組

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);

b:內建執行緒池的使用概述

弊端: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

}}

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

} borderlayout(邊界布局管理器)

gridlayout(網格布局管理器)

cardlayout(卡片布局管理器)

gridbaglayout(網格包布局管理器)

frame f = new frame("我的窗體");

//事件源是窗體,把***註冊到事件源上

//事件物件傳遞給***

f.addwindowlistener(new windowadapter()

});

b.介面卡原理

把今天的知識點總結一遍。

day25 多執行緒 下 GUI

25.01 多執行緒 單例設計模式 掌握 單例寫法兩種 25.02 多執行緒 runtime類 25.03 多執行緒 timer 掌握 25.04 多執行緒 兩個執行緒間的通訊 掌握 2.怎麼通訊 25.05 多執行緒 三個或三個以上間的執行緒通訊 1.同步 2.通訊 25.07 多執行緒 執行緒組...

每日演算法 day 25

那些你早出晚歸付出的刻苦努力,你不想訓練,當你覺的太累了但還是要咬牙堅持的時候,那就是在追逐夢想,不要在意終點有什麼,要享受路途的過程,或許你不能成就夢想,但一定會有更偉大的事情隨之而來。mamba out 2020.3.10 貪心問題注意策略得轉化 別要死於固定得暴力形式,雖然是貪心思想實現起來也...

python學習歷程day25

今天學習了 1.反射 getattr 物件,字串 在物件中找字串 hasattr 物件,字串 判斷字串是否出現在物件中 setattr 物件,字串 在物件中新增字串 delattr 物件,字串 在物件中刪除字串 物件 包括模組,類,函式,方法,變數 字串 包括類,函式,方法,變數 isinstanc...