多執行緒簡單操作

2021-10-11 20:59:02 字數 1043 閱讀 1888

消費者和生產者關係實現同步:(以購進和售賣20本書為例)

//消費者和生產者的關係實現同步。

class book

system.out.println("售賣書籍為"+" "+total);

flag=false;

notify();

return total;

} public synchronized void settotal(int total) throws interruptedexception

this.total=total;

system.out.println("購進書籍為"+" "+total);

flag=true;

notify();

} }class getthread extends thread

public void run()

} catch (interruptedexception e) }}

class setthread extends thread

public void run()

} catch (exception e) }}

public class xiangcheng

}

隨機偶數和奇數的產生

class child_runnable implements runnable 

public void run() catch (interruptedexception e)

} } }

public class oj

}

三個視窗售賣票數例項(以20張為例)

//請注意將cpu切換為乙個

class kids_runnable implements runnable

catch (interruptedexception e)

} }}public class xiangcheng_caozuo

}

僅供學習參考使用。

多執行緒 佇列的簡單操作

nsoperationqueue queue nsoperationqueue alloc init queue.maxconcurrentoperationcount 2 執行緒池中的執行緒數,也就是併發運算元。預設情況下是 1,1表示沒有限制,這樣會同時執行佇列中的全部的操作。for nsint...

多執行緒簡單示例。。。

插入兩個list box,分別為 idc list1 和 idc list2 再插入乙個按鈕,為 idc button1 caption為 run 效果圖如下 雙擊 run 按鈕,新建 onbtnrun 函式。如下 void cmultthreadsdlg onbtnrun 在cmultthread...

多執行緒簡單示例

原文 多執行緒簡單示例 using system using system.collections.generic using system.linq using system.text using system.threading using system.runtime.remoting.mes...