欢迎来到代码驿站!

JAVA代码

当前位置:首页 > 软件编程 > JAVA代码

模拟打印机排队打印效果

时间:2021-01-24 11:07:19|栏目:JAVA代码|点击:
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;
}
}

上一篇:基于spring boot 2和shiro实现身份验证案例

栏    目:JAVA代码

下一篇:Spring集成webSocket页面访问404问题的解决方法

本文标题:模拟打印机排队打印效果

本文地址:http://www.codeinn.net/misctech/50226.html

推荐教程

广告投放 | 联系我们 | 版权申明

重要申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:914707363 | 邮箱:codeinn#126.com(#换成@)

Copyright © 2020 代码驿站 版权所有