繼承關(guān)系
先看源碼:Thread 類實(shí)現(xiàn)了 Runnable 接口
public
class Thread implements Runnable {
而 Runnable 被@FunctionalInterface 注解標(biāo)記為函數(shù)式接口,Runnable 接口源代碼
@FunctionalInterface
public interface Runnable {
public abstract void run();
}
再來看看@FunctionalInterface 注解的源碼
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface FunctionalInterface {}
FunctionalInterface 用于標(biāo)記類或接口是否是一個(gè)函數(shù)式接口,并在運(yùn)行時(shí)可用于反射獲取信息。
Thread 類源碼解析
加載本地資源
private static native void registerNatives();
static {
registerNatives();
}
這段代碼是 Thread 類的一個(gè)靜態(tài)初始化塊。它包含了兩個(gè)關(guān)鍵的部分:registerNatives() 方法和靜態(tài)初始化塊。文章來源:http://www.zghlxwxcb.cn/news/detail-698794.html
registerNatives() 方法:
registerNatives() 是一個(gè)本地方法,即它是用本地代碼(通常是用 C 或 C++ 編寫的)實(shí)文章來源地址http://www.zghlxwxcb.cn/news/detail-698794.html
到了這里,關(guān)于深入理解高并發(fā)編程 - 深度解析Thread 類的源碼的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!