/**
* Queues for logging, Concurrentlinkedqueue <br/>
* This queue sorts the elements according to FIFO (first-in first Out) principles, as detailed in J2se_api or JDK
* @author RSun
* 2012-2-22 05:05:19
*/
public class Systemlogqueue {
private static queue<log> Log_queue;
static{
if (null = = Log_queue) {
Log_queue = new concurrentlinkedqueue<log> (); Line-free secure queues based on link nodes
}
}
/** Initialization Creation Queue **/
public static void Init () {
if (null = = Log_queue) {
Log_queue = new concurrentlinkedqueue<log> (); Line-free secure queues based on link nodes
}
}
/**
* Add to the queue method, inserting the specified element to the end of the queue.
* @param log Log Object
* @return return True successfully, otherwise throw illegalstateexception
*/
public static Boolean Add (log log) {
Return (Log_queue.add (log));
}
/** gets and removes the header of this queue and returns null if the queue is empty.
public static Log Getpoll () {
Return (Log_queue.poll ());
}
/** gets but does not remove the header of this queue, or returns null if this queue is empty **/
public static Log Getpeek () {
Return (Log_queue.peek ());
}
/** determines whether this queue has elements and does not return true **/
public static Boolean IsEmpty () {
Return (Log_queue.isempty ());
}
/** gets size, slower **/
public static int getqueuesize () {
Return (Log_queue.size ());
}
public static void Main (string[] args) {
System.out.println ("Whether the queue has elements:" +!isempty ());
Log log = new log ();
Log_queue.add (log);
System.out.println ("Whether the queue has elements:" +!isempty ());
Log log2 = new log ();
Log2.setdate (New Date ());
Log2.setvalue ("hahaha");
Log_queue.add (LOG2);
System.out.println ("Number of queue elements:" + getqueuesize ());
Log L = Getpeek ();
System.out.println ("\ n Get Queue data:" + l.getvalue () + "---" + l.getdate ());
System.out.println ("Number of queue elements:" + getqueuesize ());
for (int i = 0; i < 2; i++) {
Log L2 = Getpoll ();
if (L2!= null) {
System.out.println ("\ n get queue data and delete:" + l2.getvalue () + "---" + l2.getdate ());
}
System.out.println ("Number of queue elements:" + getqueuesize ());
}
Whether the queue has elements: false
Whether the queue has elements: true
Number of queue elements: 2
Get queue data: null---NULL
Number of queue elements: 2
Get Queue data and delete: null---NULL
Number of queue elements: 1
Get Queue data and delete: hahaha---Thu Nov 13:58:02 CST 2012
Number of queue elements: 0
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