아날로그 프린터 줄 서기 인쇄 효과


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;
}
}

좋은 웹페이지 즐겨찾기