模擬打印機(jī)排隊(duì)打印效果
更新時(shí)間:2014年07月31日 09:54:10 投稿:whsnow
本節(jié)主要介紹了模擬打印機(jī)排隊(duì)打印效果的具體實(shí)現(xiàn),感興趣的朋友可以參考下
package com.cooly; import java.util.LinkedList; /** * @author coolyqq *模擬打印打印機(jī)排隊(duì)打印 *分發(fā)類 */ public class DataDistribute { private static DataDistribute instance = null; private final static byte[] obj = new byte[0];//鎖機(jī)制 private LinkedList<DataDistributeEntity> tasks = null;//分發(fā)任務(wù) private boolean isColse = true; private DataDistribute() { tasks = new LinkedList<DataDistributeEntity>(); } /** * @return * 獲取instance */ public static DataDistribute getInstance(){ if(instance == null){ synchronized (obj) { if(instance == null){ instance = new DataDistribute(); } } } return instance ; } /** * @param entity * 添加任務(wù) */ public void addTask(DataDistributeEntity entity){ synchronized (obj) { tasks.add(entity); } } /** * @param entity * 立即添加任務(wù) */ public void addSpeedTask(DataDistributeEntity entity){ synchronized (obj) { tasks.addFirst(entity); } } public void start(ICallBack callback){ if(tasks==null||tasks.isEmpty()||!this.isColse){ return; }else{ this.isColse = false; } while(true){ DataDistributeEntity entity = tasks.poll(); if(entity==null){ this.isColse = true; break; } callback.call(entity); tasks.remove(entity); } System.out.println("fsf"); } public boolean isColse() { return isColse; } public void setColse(boolean isColse) { this.isColse = isColse; } }
相關(guān)文章
詳解Spring-Cloud2.0之Feign調(diào)用遠(yuǎn)程服務(wù)指南
這篇文章主要介紹了詳解Spring-Cloud2.0之Feign調(diào)用遠(yuǎn)程服務(wù)指南,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2019-01-01springboot使用定時(shí)器@Scheduled不管用的解決
這篇文章主要介紹了springboot使用定時(shí)器@Scheduled不管用的解決方案,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2021-12-12