KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openide > util > Queue


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.openide.util;
21
22 import java.util.LinkedList JavaDoc;
23
24 /** Queue of objects. When there is no object in the queue the process
25 * is suspended till some arrives.
26 * Implementation appears to be LIFO.
27 *
28 * @author Jaroslav Tulach
29 * @deprecated Use {@link java.util.concurrent.BlockingQueue} instead.
30 */

31 @Deprecated JavaDoc
32 public class Queue<T> extends Object JavaDoc {
33     /** Queue enumeration */
34     private LinkedList JavaDoc<T> queue = new LinkedList JavaDoc<T>();
35
36     /** Adds new item.
37     * @param o object to add
38     */

39     public synchronized void put(T o) {
40         queue.add(o);
41         notify();
42     }
43
44     /** Gets an object from the queue. If there is no such object the
45     * thread is suspended until some object arrives
46     *
47     * @return object from the queue
48     */

49     public synchronized T get() {
50         for (;;) {
51             if (queue.isEmpty()) {
52                 try {
53                     wait();
54                 } catch (InterruptedException JavaDoc ex) {
55                 }
56             } else {
57                 break;
58             }
59         }
60
61         return queue.removeFirst();
62     }
63 }
64
Popular Tags