我正在實現TCP的簡單版本,但缺乏多線程技術。主線程控制2個線程:處理多線程事件
1.定時器(倒計時時間,如果超時,通知主線程再做一些工作)
2.永遠聽傳入的數據包,循環。如果接收到數據包,則更新主線程中的一些數據
主線程在發生某些信號時應採取措施。
我沒有事件處理的經驗和設計一些信號通知主線程。 我應該從哪裏開始?例如,子線程更新主線程專用字段。或者我應該創建一些事件?
這裏的主線程一些僞代碼:
while(true){
event: send data ,then ...
event: timeout , then send packet again
event: packet received, then update data in private filed
}
你做了什麼研究?你看過什麼網絡資源? – Gray
@Grey http://docs.oracle.com/javase/tutorial/essential/concurrency/pools.html和Excutor接口,BlockingQueue接口 – CodeFarmer