- /**
- * 隊列服務.用來查看線程隊排中的請求.
- * 啓動一個線程,用來跟蹤隊排裏的客戶請求.
- * 如果隊中有客戶的請求,則創建一個新線程獨立處理,<br>
- * @author guishuanglin 2008-11-3
- *
- */
- public class ConcurrentQueueService extends Thread {
- //IConcurrentCall
- private ConcurrentQueue _queue;
- /**
- * 啓動一個線程來跟蹤堆中需要處理的對象.
- * @param queue
- */
- public ConcurrentQueueService(ConcurrentQueue queue) {
- _queue = queue;
- start();
- }
- /**
- * 入隊
- * @param call
- */
- public void enQueue(IConcurrentCall target) {
- _queue.enQueue(target);
- }
- /**
- * 單一線程跟蹤隊排請求,並把每個請求交給一個新線程處理.
- * 此處是否需要創建新的線程處理,有待實際需要,因爲這將又產生線程併發問題.
- * @param call
- */
- public void run() {
- Runnable call = null;
- while (true) {
- call = (Runnable)_queue.deQueue();
- if(call != null){
- //可以不使用獨立的線程處理,直接順序處理.
- call.run();
- //new Thread(call).start();
- }
- }
- }
- }
jdk1.4 構建 java多線程,併發設計框架 (三)
啓動一個線程,用來跟蹤隊排裏的客戶請求
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.