Simulate printer queued Print effect _java

Source: Internet
Author: User
Package com.cooly;

Import java.util.LinkedList; /** * @author COOLYQQ * Analog Print printer queued print * Distribution class * * public class Datadistribute {private static Datadistribute instance = NULL; p Rivate final static byte[] obj = new byte[0];//lock mechanism private linkedlist<datadistributeentity> tasks = null;//Distribution Task Priv
Ate Boolean iscolse = true;

Private Datadistribute () {tasks = new linkedlist<datadistributeentity> ();} /** * @return * Get instance/public static Datadistribute getinstance () {if (instance = null) {synchronized (obj) {if (in
stance = = NULL) {instance = new Datadistribute ();}}
return instance; 
/** * @param entity * Add task/public void AddTask (datadistributeentity entity) {synchronized (obj) {tasks.add (entity); }/** * @param entity * Add task now/public void Addspeedtask (datadistributeentity entity) {synchronized (obj) {tasks.ad
DFirst (entity); } public void Start (Icallback callback) {if tasks==null| | Tasks.isempty () | |! This.iscolse) {return;} else{This.iscolse = false;(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;}}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.