package com.cooly;import java.util.LinkedList;/*** @author coolyqq*Drucken der Druckerwarteschlange simulieren*Verteilungsklasse*/öffentliche Klasse DataDistribute {private static DataDistribute example = null;private final static byte[] obj = new byte[0];//Sperrmechanismus private LinkedList<DataDistributeEntity> task = null;//Verteilungsaufgaben private boolean isColse = true;private DataDistribute() {tasks = new LinkedList<DataDistributeEntity>();}/*** @return* Instanz abrufen*/public static DataDistribute getInstance(){if(instance == null){synchronized (obj) {if(instance == null) {instance = new DataDistribute();}}}return instance ;}/*** @param entity* Aufgabe hinzufügen*/public void addTask(DataDistributeEntity entity){synchronized (obj) {tasks.add(entity);}}/*** @param entity* Aufgaben sofort hinzufügen*/public void addSpeedTask(DataDistributeEntity entity){synchronized (obj) {tasks.addFirst(entity); }}public void start(ICallBack Rückruf){if(tasks==null||tasks.isEmpty()||!this.isColse){return;}else{this.isColse = false;}while(true){DataDistributeEntity entity = task.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;}}