亲宝软件园·资讯

展开

打印机排队打印 模拟打印机排队打印效果

人气:1
想了解模拟打印机排队打印效果的相关内容吗,在本文为您仔细讲解打印机排队打印的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:打印机,排队打印,下面大家一起来学习吧。
package com.cooly;

import java.util.LinkedList;

/**
* @author coolyqq
*模拟打印打印机排队打印
*分发类
*/
public class DataDistribute {

private static DataDistribute instance = null;
private final static byte[] obj = new byte[0];//锁机制
private LinkedList<DataDistributeEntity> tasks = null;//分发任务
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;
}
}

加载全部内容

相关教程
猜你喜欢
用户评论