google關於事件的生產者消費者模式實現例子

2021-09-02 09:35:25 字數 1184 閱讀 1833

google使用生產者/消費者模式實現了事件的產生傳播處理過程,也就是事件的產生與訂閱。

這裡通過乙個簡單的例子來測試執行。

1.定義事件

package com.event;

/***

* @author yangjianzhou

** jan 24, 2015 11:19:09 am

* * 定義事件

*/public class testevent

public string getname()

}

2.定義事件***

package com.listener;

import com.event.testevent;

import com.google.common.eventbus.subscribe;

/***

* @author yangjianzhou

** jan 24, 2015 11:09:40 am

* * 監聽事件,然後處理

*/public class testlistener

@subscribe

public void processtwo(testevent event)

}

3.測試程式

package com.test;

import com.event.testevent;

import com.google.common.eventbus.eventbus;

import com.listener.testlistener;

/***

* @author yangjianzhou

** jan 24, 2015 11:12:06 am

* * 事件測試

*/public class testeventlistener

}

4.執行結果:

this is processtwo : yangjianzhou

this is processone : yangjianzhou

NSCondition 多執行緒解決生產者消費者問題

import viewcontroller.h inte ce viewcontroller 資料緩衝區 property strong,nonatomic nsmutablearray products 執行緒鎖 property strong,nonatomic nscondition cond...

生產者Confirm訊息與Return訊息機制

訊息的確認,是指生產者投遞訊息後,如果broker收到訊息,則會給我們生產者乙個應答 生產者接收應答,用來確定這條訊息是否正常傳送到broker,這種方式也是訊息的可靠性傳遞的核心保障 channel開啟確認模式 channel.confirmselect 在channel上加監聽 addconfi...

Go 關於 kafka 的生產者 消費者例項

bin 目錄下包含了服務的啟動指令碼 啟動 zookeeper bin zookeeper server start.sh config zookeeper.properties啟動 kafka server bin kafka server start.sh config server.prope...