模拟打印机排队打印效果
作者:whsnow 时间:2023-12-13 13:26:22
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;
}
}
标签:打印机,排队打印
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Java数据结构与算法之单链表深入理解
2023-12-02 05:53:12
![](https://img.aspxhome.com/file/2023/3/128833_0s.png)
C语言入门篇--初识指针和指针变量
2022-05-31 06:10:45
![](https://img.aspxhome.com/file/2023/3/120803_0s.png)
使用adb命令向Android模拟器中导入通讯录联系人的方法
2022-12-21 15:39:56
CefSharp过滤图片RequestHandler问题
2023-06-05 03:01:39
C#.net中的类型转换详细介绍
2021-09-20 04:14:01
详解Java Spring AOP
2023-09-06 15:40:02
![](https://img.aspxhome.com/file/2023/1/92641_0s.png)
使用SSM+Layui+Bootstrap实现汽车维保系统的示例代码
2023-11-28 18:30:04
![](https://img.aspxhome.com/file/2023/6/60416_0s.jpg)
有关Java中的BeanInfo介绍
2023-08-05 00:13:42
![](https://img.aspxhome.com/file/2023/5/57955_0s.jpg)
C# 通过ServiceStack 操作Redis
2023-12-13 06:18:01
![](https://img.aspxhome.com/file/2023/2/80022_0s.png)
浅谈java中String的两种赋值方式的区别
2021-09-21 23:59:36
![](https://img.aspxhome.com/file/2023/4/69894_0s.jpg)
C#的回调机制浅析
2022-04-06 19:10:32
解析Java线程同步锁的选择方法
2023-02-08 11:02:32
关于Kotlin写界面时诸多控件的点击事件
2023-01-28 12:34:51
![](https://img.aspxhome.com/file/2023/5/137585_0s.jpg)
Java日常练习题,每天进步一点点(32)
2022-04-29 07:12:53
如何使用Android注解处理器
2023-08-16 16:49:05
![](https://img.aspxhome.com/file/2023/8/139418_0s.jpg)
Android EditText密码的隐藏和显示功能
2021-11-17 16:49:47
![](https://img.aspxhome.com/file/2023/8/89508_0s.png)
C#实现一个控制台的点餐系统
2023-09-03 20:47:24
![](https://img.aspxhome.com/file/2023/1/113881_0s.jpg)
JavaWeb实现多文件上传及zip打包下载
2023-11-16 16:41:25
从零开始学springboot整合feign跨服务调用的方法
2023-05-15 18:30:22
![](https://img.aspxhome.com/file/2023/5/81895_0s.png)
Android clipChildren属性实例详解
2022-12-29 02:35:50
![](https://img.aspxhome.com/file/2023/9/139289_0s.png)