模拟打印机排队打印效果
更新时间:2014年07月31日 09:54:10 投稿:whsnow
本节主要介绍了模拟打印机排队打印效果的具体实现,感兴趣的朋友可以参考下
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;
}
}
您可能感兴趣的文章:
相关文章
SpringBoot使用@Slf4j注解实现日志输出的示例代码
@Slf4j 是 Lombok 库中的一个注解,它极大地简化了日志记录的代码,通过使用这个注解,Lombok 会自动在你的类中注入一个静态的日志对象,本文给大家介绍了SpringBoot使用@Slf4j注解实现日志输出的方法,需要的朋友可以参考下2024-10-10
SpringBoot中集成screw(螺丝钉)实现数据库表结构文档生成方法
这篇文章主要介绍了SpringBoot中集成screw(螺丝钉)实现数据库表结构文档生成,下面以连接mysql数据库并生成html格式的数据库结构文档为例,插件的使用方式除可以使用代码外,还可以使用Maven插件的方式,需要的朋友可以参考下2024-07-07


最新评论