資源簡介
東北大學操作系統實驗Java代碼,最新,可供參考使用。
(學長學姐也是這樣一步步過來的,實驗還是要自己動手完成才有收獲)
(學長學姐也是這樣一步步過來的,實驗還是要自己動手完成才有收獲)

代碼片段和文件信息
import?java.util.linkedList;
public?class?Basket?{
????//basket的最大數量為10
????public?linkedList?store=new?linkedList();
????public??linkedListgetStore(){
????????return??store;
????}
????public??void??setStore(linkedList?store){
????????this.store=store;
????}
????//生產者方法
????public??synchronized??void?push(Product?productString?threadName)?{
????????
????????while?(store.size()?==?10)?{
????????????try?{
????????????????System.out.println(threadName?+?“ATTENTION?-->?the?basket?is?full?now?-->?enter?the?waiting?condition?-->?tell?the?consumer?to?consume“);
????????????????//the?basket?is?full
????????????????this.wait();
????????????}?catch?(InterruptedException?e)?{
????????????????e.printStackTrace();
????????????}
????????}
????????//wake?up?all
????????this.notifyAll();
????????//put?the?product?into?the?basket
????????store.addLast(product);
????????//print?the?product?log
????????System.out.println(?threadName?+?“??has?produced??production?“?+?product.getId()?+?“?????util?now??the?basket??has?“?+?store.size()?+?“?product“);
????????try?{
????????????//線程睡眠
????????????Thread.sleep(500);
????????}?catch?(InterruptedException?e)?{
????????????e.printStackTrace();
????????}
????}
????//消費者方法
????public?synchronized??void??pop(String?threadName){
????????
????????while(store.size()==0){
????????????try?{
????????????????????System.out.println(threadName?+?“?the?basket?is?empty?-->?wait?state?-->?tell?the?producer?to?product?“);
????????????????????//the?basket?is?fullso?enter?the?waiting?condition
????????????????????this.wait();
????????????????}catch?(InterruptedException?e){
????????????????e.printStackTrace();
????????????}
????????}
????????//wake?up?all;
????????this.notifyAll();
????????//remove?the?production?from?the?basket
????????System.out.println(threadName+“?has?consumed?“+“production?“+store.removeFirst().getId()+“?????util?now?the?capacity?is?“?+
???????????????store.size());
????????try?{
????????????//waiting?1s?every?time?after?each?produced?to?watch?more?convenient
????????????Thread.sleep(1000);
????????????}catch?(InterruptedException?e){
????????????e.printStackTrace();
????????}
????}
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????2272??2018-12-31?15:11??東北大學操作系統實驗\實驗1生產者消費者問題\Basket.java
?????文件????????318??2018-12-31?15:11??東北大學操作系統實驗\實驗1生產者消費者問題\Consumer.java
?????文件????????540??2018-12-31?15:11??東北大學操作系統實驗\實驗1生產者消費者問題\Producer.java
?????文件????????237??2018-12-31?15:11??東北大學操作系統實驗\實驗1生產者消費者問題\Product.java
?????文件????????853??2018-12-31?15:11??東北大學操作系統實驗\實驗1生產者消費者問題\Test.java
?????文件????????773??2018-12-31?15:14??東北大學操作系統實驗\實驗2時間片輪轉法\PCB.java
?????文件???????3459??2018-12-31?15:14??東北大學操作系統實驗\實驗2時間片輪轉法\RR.java
?????文件????????151??2018-12-31?15:14??東北大學操作系統實驗\實驗2時間片輪轉法\test.java
?????文件???????1410??2018-12-31?15:16??東北大學操作系統實驗\實驗3\題目一\Simulate.java
?????文件????????140??2018-12-31?15:16??東北大學操作系統實驗\實驗3\題目一\Table.java
?????文件???????2291??2018-12-31?15:16??東北大學操作系統實驗\實驗3\題目二\Simulate.java
?????文件????????152??2018-12-31?15:16??東北大學操作系統實驗\實驗3\題目二\Table.java
?????文件????????560??2018-12-31?15:17??東北大學操作系統實驗\實驗4文件管理系統\AFD.java
?????文件???????1559??2018-12-31?15:17??東北大學操作系統實驗\實驗4文件管理系統\Login.java
?????文件????????416??2018-12-31?15:17??東北大學操作系統實驗\實驗4文件管理系統\MDF.java
?????文件???????6695??2018-12-31?15:17??東北大學操作系統實驗\實驗4文件管理系統\MyFile.java
?????文件????????703??2018-12-31?15:17??東北大學操作系統實驗\實驗4文件管理系統\UFD.java
?????目錄??????????0??2019-02-27?13:38??東北大學操作系統實驗\實驗3\題目一
?????目錄??????????0??2019-02-27?13:38??東北大學操作系統實驗\實驗3\題目二
?????目錄??????????0??2019-02-27?13:38??東北大學操作系統實驗\實驗1生產者消費者問題
?????目錄??????????0??2019-02-27?13:38??東北大學操作系統實驗\實驗2時間片輪轉法
?????目錄??????????0??2019-02-27?13:38??東北大學操作系統實驗\實驗3
?????目錄??????????0??2019-02-27?13:38??東北大學操作系統實驗\實驗4文件管理系統
?????目錄??????????0??2019-02-27?13:39??東北大學操作系統實驗
-----------?---------??----------?-----??----
????????????????22529????????????????????24
- 上一篇:XposedBridgeAPI-89.jar
- 下一篇:Java實現對文檔的加密解密
評論
共有 條評論