Java Doc for SynchronousQueue.java in  » 6.0-JDK-Core » Collections-Jar-Zip-Logging-regex » java » util » concurrent » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Home
Java Source Code / Java Documentation
1.6.0 JDK Core
2.6.0 JDK Modules
3.6.0 JDK Modules com.sun
4.6.0 JDK Modules com.sun.java
5.6.0 JDK Modules sun
6.6.0 JDK Platform
7.Ajax
8.Apache Harmony Java SE
9.Aspect oriented
10.Authentication Authorization
11.Blogger System
12.Build
13.Byte Code
14.Cache
15.Chart
16.Chat
17.Code Analyzer
18.Collaboration
19.Content Management System
20.Database Client
21.Database DBMS
22.Database JDBC Connection Pool
23.Database ORM
24.Development
25.EJB Server
26.ERP CRM Financial
27.ESB
28.Forum
29.Game
30.GIS
31.Graphic 3D
32.Graphic Library
33.Groupware
34.HTML Parser
35.IDE
36.IDE Eclipse
37.IDE Netbeans
38.Installer
39.Internationalization Localization
40.Inversion of Control
41.Issue Tracking
42.J2EE
43.J2ME
44.JBoss
45.JMS
46.JMX
47.Library
48.Mail Clients
49.Music
50.Net
51.Parser
52.PDF
53.Portal
54.Profiler
55.Project Management
56.Report
57.RSS RDF
58.Rule Engine
59.Science
60.Scripting
61.Search Engine
62.Security
63.Sevlet Container
64.Source Control
65.Swing Library
66.Template Engine
67.Test Coverage
68.Testing
69.UML
70.Web Crawler
71.Web Framework
72.Web Mail
73.Web Server
74.Web Services
75.Web Services apache cxf 2.2.6
76.Web Services AXIS2
77.Wiki Engine
78.Workflow Engines
79.XML
80.XML UI
Java Source Code / Java Documentation » 6.0 JDK Core » Collections Jar Zip Logging regex » java.util.concurrent 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.util.concurrent.SynchronousQueue

SynchronousQueue
public class SynchronousQueue extends AbstractQueue implements BlockingQueue<E>,java.io.Serializable(Code)
A in which each insert operation must wait for a corresponding remove operation by another thread, and vice versa. A synchronous queue does not have any internal capacity, not even a capacity of one. You cannot peek at a synchronous queue because an element is only present when you try to remove it; you cannot insert an element (using any method) unless another thread is trying to remove it; you cannot iterate as there is nothing to iterate. The head of the queue is the element that the first queued inserting thread is trying to add to the queue; if there is no such queued thread then no element is available for removal and poll() will return null. For purposes of other Collection methods (for example contains), a SynchronousQueue acts as an empty collection. This queue does not permit null elements.

Synchronous queues are similar to rendezvous channels used in CSP and Ada. They are well suited for handoff designs, in which an object running in one thread must sync up with an object running in another thread in order to hand it some information, event, or task.

This class supports an optional fairness policy for ordering waiting producer and consumer threads. By default, this ordering is not guaranteed. However, a queue constructed with fairness set to true grants threads access in FIFO order.

This class and its iterator implement all of the optional methods of the Collection and Iterator interfaces.

This class is a member of the Java Collections Framework.
since:
   1.5
author:
   Doug Lea and Bill Scherer and Michael Scott<
Parameters:
  E - > the type of elements held in this collection


Inner Class :abstract static class Transferer
Inner Class :final static class TransferStack extends Transferer
Inner Class :final static class TransferQueue extends Transferer
Inner Class :static class WaitQueue implements java.io.Serializable
Inner Class :static class LifoWaitQueue extends WaitQueue
Inner Class :static class FifoWaitQueue extends WaitQueue

Field Summary
final static  intNCPUS
    
final static  intmaxTimedSpins
     The number of times to spin before blocking in timed waits. The value is empirically derived -- it works well across a variety of processors and OSes.
final static  intmaxUntimedSpins
     The number of times to spin before blocking in untimed waits.
final static  longspinForTimeoutThreshold
     The number of nanoseconds for which it is faster to spin rather than to use timed park.

Constructor Summary
public  SynchronousQueue()
     Creates a SynchronousQueue with nonfair access policy.
public  SynchronousQueue(boolean fair)
     Creates a SynchronousQueue with the specified fairness policy.

Method Summary
public  voidclear()
     Does nothing.
public  booleancontains(Object o)
     Always returns false.
public  booleancontainsAll(Collection c)
     Returns false unless the given collection is empty.
public  intdrainTo(Collection<? super E> c)
    
public  intdrainTo(Collection<? super E> c, int maxElements)
    
public  booleanisEmpty()
     Always returns true.
public  Iterator<E>iterator()
     Returns an empty iterator in which hasNext always returns false.
public  booleanoffer(E o, long timeout, TimeUnit unit)
     Inserts the specified element into this queue, waiting if necessary up to the specified wait time for another thread to receive it.
public  booleanoffer(E e)
     Inserts the specified element into this queue, if another thread is waiting to receive it.
public  Epeek()
     Always returns null.
public  Epoll(long timeout, TimeUnit unit)
     Retrieves and removes the head of this queue, waiting if necessary up to the specified wait time, for another thread to insert it.
public  Epoll()
     Retrieves and removes the head of this queue, if another thread is currently making an element available.
public  voidput(E o)
     Adds the specified element to this queue, waiting if necessary for another thread to receive it.
public  intremainingCapacity()
     Always returns zero.
public  booleanremove(Object o)
     Always returns false.
public  booleanremoveAll(Collection c)
     Always returns false.
public  booleanretainAll(Collection c)
     Always returns false.
public  intsize()
     Always returns zero.
public  Etake()
     Retrieves and removes the head of this queue, waiting if necessary for another thread to insert it.
public  Object[]toArray()
     Returns a zero-length array.
public  T[]toArray(T[] a)
     Sets the zeroeth element of the specified array to null (if the array has non-zero length) and returns it.

Field Detail
NCPUS
final static int NCPUS(Code)
The number of CPUs, for spin control



maxTimedSpins
final static int maxTimedSpins(Code)
The number of times to spin before blocking in timed waits. The value is empirically derived -- it works well across a variety of processors and OSes. Empirically, the best value seems not to vary with number of CPUs (beyond 2) so is just a constant.



maxUntimedSpins
final static int maxUntimedSpins(Code)
The number of times to spin before blocking in untimed waits. This is greater than timed value because untimed waits spin faster since they don't need to check times on each spin.



spinForTimeoutThreshold
final static long spinForTimeoutThreshold(Code)
The number of nanoseconds for which it is faster to spin rather than to use timed park. A rough estimate suffices.




Constructor Detail
SynchronousQueue
public SynchronousQueue()(Code)
Creates a SynchronousQueue with nonfair access policy.



SynchronousQueue
public SynchronousQueue(boolean fair)(Code)
Creates a SynchronousQueue with the specified fairness policy.
Parameters:
  fair - if true, waiting threads contend in FIFO order foraccess; otherwise the order is unspecified.




Method Detail
clear
public void clear()(Code)
Does nothing. A SynchronousQueue has no internal capacity.



contains
public boolean contains(Object o)(Code)
Always returns false. A SynchronousQueue has no internal capacity.
Parameters:
  o - the element false



containsAll
public boolean containsAll(Collection c)(Code)
Returns false unless the given collection is empty. A SynchronousQueue has no internal capacity.
Parameters:
  c - the collection false unless given collection is empty



drainTo
public int drainTo(Collection<? super E> c)(Code)

throws:
  UnsupportedOperationException -
throws:
  ClassCastException -
throws:
  NullPointerException -
throws:
  IllegalArgumentException -



drainTo
public int drainTo(Collection<? super E> c, int maxElements)(Code)

throws:
  UnsupportedOperationException -
throws:
  ClassCastException -
throws:
  NullPointerException -
throws:
  IllegalArgumentException -



isEmpty
public boolean isEmpty()(Code)
Always returns true. A SynchronousQueue has no internal capacity. true



iterator
public Iterator<E> iterator()(Code)
Returns an empty iterator in which hasNext always returns false. an empty iterator



offer
public boolean offer(E o, long timeout, TimeUnit unit) throws InterruptedException(Code)
Inserts the specified element into this queue, waiting if necessary up to the specified wait time for another thread to receive it. true if successful, or false if thespecified waiting time elapses before a consumer appears.
throws:
  InterruptedException -
throws:
  NullPointerException -



offer
public boolean offer(E e)(Code)
Inserts the specified element into this queue, if another thread is waiting to receive it.
Parameters:
  e - the element to add true if the element was added to this queue, elsefalse
throws:
  NullPointerException - if the specified element is null



peek
public E peek()(Code)
Always returns null. A SynchronousQueue does not return elements unless actively waited on. null



poll
public E poll(long timeout, TimeUnit unit) throws InterruptedException(Code)
Retrieves and removes the head of this queue, waiting if necessary up to the specified wait time, for another thread to insert it. the head of this queue, or null if thespecified waiting time elapses before an element is present.
throws:
  InterruptedException -



poll
public E poll()(Code)
Retrieves and removes the head of this queue, if another thread is currently making an element available. the head of this queue, or null if noelement is available.



put
public void put(E o) throws InterruptedException(Code)
Adds the specified element to this queue, waiting if necessary for another thread to receive it.
throws:
  InterruptedException -
throws:
  NullPointerException -



remainingCapacity
public int remainingCapacity()(Code)
Always returns zero. A SynchronousQueue has no internal capacity. zero.



remove
public boolean remove(Object o)(Code)
Always returns false. A SynchronousQueue has no internal capacity.
Parameters:
  o - the element to remove false



removeAll
public boolean removeAll(Collection c)(Code)
Always returns false. A SynchronousQueue has no internal capacity.
Parameters:
  c - the collection false



retainAll
public boolean retainAll(Collection c)(Code)
Always returns false. A SynchronousQueue has no internal capacity.
Parameters:
  c - the collection false



size
public int size()(Code)
Always returns zero. A SynchronousQueue has no internal capacity. zero.



take
public E take() throws InterruptedException(Code)
Retrieves and removes the head of this queue, waiting if necessary for another thread to insert it. the head of this queue
throws:
  InterruptedException -



toArray
public Object[] toArray()(Code)
Returns a zero-length array. a zero-length array



toArray
public T[] toArray(T[] a)(Code)
Sets the zeroeth element of the specified array to null (if the array has non-zero length) and returns it.
Parameters:
  a - the array the specified array
throws:
  NullPointerException - if the specified array is null



www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.