JDK并发包中的接口(抽象类)的定义

    xiaoxiao2023-11-03  162

    Locks

    1、AbstractOwnableSynchronizer

    public abstract class AbstractOwnableSynchronizer implements java.io.Serializable { protected AbstractOwnableSynchronizer() { } private transient Thread exclusiveOwnerThread; protected final void setExclusiveOwnerThread(Thread thread) { exclusiveOwnerThread = thread; } protected final Thread getExclusiveOwnerThread() { return exclusiveOwnerThread; } }

    2、Lock

    public interface Lock { void lock(); void lockInterruptibly() throws InterruptedException; boolean tryLock(); boolean tryLock(long time, TimeUnit unit) throws InterruptedException; void unlock(); Condition newCondition(); }

    3、Condition

    public interface Condition { void await() throws InterruptedException; void awaitUninterruptibly(); long awaitNanos(long nanosTimeout) throws InterruptedException; boolean await(long time, TimeUnit unit) throws InterruptedException; boolean awaitUntil(Date deadline) throws InterruptedException; void signal(); void signalAll(); }

     4、ReadWriteLock

    public interface ReadWriteLock { Lock readLock(); Lock writeLock(); }

    队列

    Queue

    public interface Queue<E> extends Collection<E> { //增加一个元索 如果队列已满,则抛出一个IIIegaISlabEepeplian异常,不可加入null。 boolean add(E e); //移除并返回队列头部的元素 如果队列为空,则抛出一个NoSuchElementException异常。 E remove(); //返回队列头部的元素 如果队列为空,则抛出一个NoSuchElementException异常 E element(); //添加一个元素并返回true 如果队列已满,则返回false 。不可add null boolean offer(E e); //移除并返问队列头部的元素 如果队列为空,则返回null。 E poll(); //返回队列头部的元素 如果队列为空,则返回null。 E peek(); }

    BlockingQueue

    public interface BlockingQueue<E> extends Queue<E> { //将给定元素设置到队列中,如果设置成功返回true, 否则返回false。如果是往限定了长度的队列中设置值,推荐使用offer()方法。 如果队列已满,则抛出一个IIIegaISlabEepeplian异常,不可add null boolean add(E e); //将给定的元素设置到队列中,如果设置成功返回true, 否则返回false. e的值不能为空,否则抛出空指针异常。 boolean offer(E e); //将元素设置到队列中,如果队列中没有多余的空间,该方法会一直阻塞,直到队列中有多余的空间。 void put(E e) throws InterruptedException; //将给定元素在给定的时间内设置到队列中,如果设置成功返回true, 否则返回false. boolean offer(E e, long timeout, TimeUnit unit) throws InterruptedException; //从队列中获取值,如果队列中没有值,线程会一直阻塞,直到队列中有值,并且该方法取得了该值。 E take() throws InterruptedException; //在给定的时间里,从队列中获取值,时间到了直接调用普通的poll方法,为null则直接返回null。 E poll(long timeout, TimeUnit unit) throws InterruptedException; //获取队列中剩余的空间。 int remainingCapacity(); //从队列中移除指定的值。 boolean remove(Object o); //判断队列中是否拥有该值。 public boolean contains(Object o); //将队列中值,全部移除,并发设置到给定的集合中。 int drainTo(Collection<? super E> c); //指定最多数量限制将队列中值,全部移除,并发设置到给定的集合中。 int drainTo(Collection<? super E> c, int maxElements); }

     Deque<E>

    public interface Deque<E> extends Queue<E> { /* 在队列头或尾增加或删除节点,队列满或者空抛出异常*/ void addFirst(E e); void addLast(E e); E removeFirst(); E removeLast(); /* 在队列头或尾获取节点,队列满或者空抛出异常*/ E getFirst(); E getLast(); /* 在队列头或尾增加或删除节点,队列满或者空返回false或者null*/ boolean offerFirst(E e); boolean offerLast(E e); E pollFirst(); E pollLast(); /* 在队列头或尾获取节点,队列满或者空返回false或者null*/ E peekFirst(); E peekLast(); /*移除此deque队列的指定元素的第一个或最后一个匹配*/ boolean removeFirstOccurrence(Object o); boolean removeLastOccurrence(Object o); // *** Queue methods *** boolean add(E e); boolean offer(E e); E remove(); E poll(); E element(); E peek(); // *** Stack methods *** void push(E e); E pop(); // *** Collection methods *** boolean remove(Object o); boolean contains(Object o); public int size(); Iterator<E> iterator(); Iterator<E> descendingIterator(); }

    BlockingDeque<E>

    public interface BlockingDeque<E> extends BlockingQueue<E>, Deque<E> { void addFirst(E e); void addLast(E e); boolean offerFirst(E e); boolean offerLast(E e); void putFirst(E e) throws InterruptedException; void putLast(E e) throws InterruptedException; boolean offerFirst(E e, long timeout, TimeUnit unit) throws InterruptedException; boolean offerLast(E e, long timeout, TimeUnit unit) throws InterruptedException; E takeFirst() throws InterruptedException; E takeLast() throws InterruptedException; E pollFirst(long timeout, TimeUnit unit) throws InterruptedException; E pollLast(long timeout, TimeUnit unit) throws InterruptedException; boolean removeFirstOccurrence(Object o); boolean removeLastOccurrence(Object o); // *** BlockingQueue methods *** boolean add(E e); boolean offer(E e); void put(E e) throws InterruptedException; boolean offer(E e, long timeout, TimeUnit unit) throws InterruptedException; E remove(); E poll(); E take() throws InterruptedException; E poll(long timeout, TimeUnit unit) throws InterruptedException; E element(); E peek(); boolean remove(Object o); public boolean contains(Object o); public int size(); Iterator<E> iterator(); // *** Stack methods *** void push(E e); }

     

    最新回复(0)