模擬打印機排隊打印效果
更新時間:2014年07月31日 09:54:10 投稿:whsnow
本節(jié)主要介紹了模擬打印機排隊打印效果的具體實現(xiàn),感興趣的朋友可以參考下
package com.cooly;
import java.util.LinkedList;
/**
* @author coolyqq
*模擬打印打印機排隊打印
*分發(fā)類
*/
public class DataDistribute {
private static DataDistribute instance = null;
private final static byte[] obj = new byte[0];//鎖機制
private LinkedList<DataDistributeEntity> tasks = null;//分發(fā)任務
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
* 添加任務
*/
public void addTask(DataDistributeEntity entity){
synchronized (obj) {
tasks.add(entity);
}
}
/**
* @param entity
* 立即添加任務
*/
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;
}
}
相關文章
SpringBoot使用@Slf4j注解實現(xiàn)日志輸出的示例代碼
@Slf4j 是 Lombok 庫中的一個注解,它極大地簡化了日志記錄的代碼,通過使用這個注解,Lombok 會自動在你的類中注入一個靜態(tài)的日志對象,本文給大家介紹了SpringBoot使用@Slf4j注解實現(xiàn)日志輸出的方法,需要的朋友可以參考下2024-10-10
SpringBoot中集成screw(螺絲釘)實現(xiàn)數(shù)據(jù)庫表結構文檔生成方法
這篇文章主要介紹了SpringBoot中集成screw(螺絲釘)實現(xiàn)數(shù)據(jù)庫表結構文檔生成,下面以連接mysql數(shù)據(jù)庫并生成html格式的數(shù)據(jù)庫結構文檔為例,插件的使用方式除可以使用代碼外,還可以使用Maven插件的方式,需要的朋友可以參考下2024-07-07

