浩汝烟海


  • 首页

  • 标签

  • 分类

  • 归档

  • 搜索

ArrayBlockingQueue

发表于 2018-11-13 | 分类于 源码
字数统计: 2k | 阅读时长 ≈ 8

翻译

类注释
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/**
* A bounded {@linkplain BlockingQueue blocking queue} backed by an
* array. This queue orders elements FIFO (first-in-first-out). The
* <em>head</em> of the queue is that element that has been on the
* queue the longest time. The <em>tail</em> of the queue is that
* element that has been on the queue the shortest time. New elements
* are inserted at the tail of the queue, and the queue retrieval
* operations obtain elements at the head of the queue.
*

一个有限的blocking queue由数组支持。
这个队列排列元素FIFO(先进先出)。
队列的头部是队列中最长时间的元素。 头部和尾部为什么是最长和最短告知一下我
队列的尾部是队列中最短时间的元素。
新元素插入队列的尾部,队列检索操作获取队列头部的元素


* This is a classic &quot;bounded buffer&quot;, in which a
* fixed-sized array holds elements inserted by producers and
* extracted by consumers. Once created, the capacity cannot be
* changed. Attempts to {@code put} an element into a full queue
* will result in the operation blocking; attempts to {@code take} an
* element from an empty queue will similarly block.
*

这是一个经典的“有界缓冲区”,其中固定大小的数组保存由生产者插入的元素并由消费者提取。
创建后,容量无法更改。 尝试put成满的队列的元件将导致操作阻挡;
尝试take从空队列的元件将同样地阻塞


* 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 {@code true} grants threads access in FIFO order. Fairness
* generally decreases throughput but reduces variability and avoids
* starvation.
*
此类支持可选的公平策略,用于订购等待的生产者和消费者线程。
默认情况下,此订单不能保证。 然而,以公平设置为true的队列以FIFO顺序授予线程访问权限。 公平性通常会降低吞吐量,但会降低变异性并避免饥饿

*/
阅读全文 »

BlockingQueue翻译

发表于 2018-11-11 | 分类于 源码
字数统计: 2.8k | 阅读时长 ≈ 13

翻译

类注释
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/**
* A {@link java.util.Queue} that additionally supports operations
* that wait for the queue to become non-empty when retrieving an
* element, and wait for space to become available in the queue when
* storing an element.

* A Queue额外支持在检索元素时等待队列变为非空和
在存储元素时等待队列中的空间变得可用的操作

* {@code BlockingQueue} methods come in four forms, with different ways
* of handling operations that cannot be satisfied immediately, but may be
* satisfied at some point in the future:

BlockingQueue方法有四种形式,具有不同的操作方式,不能立即满足,但可能在将来的某个时间点满足

* one throws an exception, the second returns a special value (either
* {@code null} or {@code false}, depending on the operation), the third
* blocks the current thread indefinitely until the operation can succeed,
* and the fourth blocks for only a given maximum time limit before giving
* up.
一个抛出异常,第二个返回一个特殊值( null或false ,具体取决于操作),第三个程序将无限期地阻止当前线程,直到操作成功为止,
而第四个程序块在放弃之前只有给定的最大时限。


*
* A {@code BlockingQueue} does not accept {@code null} elements.
* Implementations throw {@code NullPointerException} on attempts
* to {@code add}, {@code put} or {@code offer} a {@code null}. A
* {@code null} is used as a sentinel value to indicate failure of
* {@code poll} operations.

A BlockingQueue不接受null元素。 实现抛出NullPointerException上尝试add
put或offer一个null 。 A null用作哨兵值以指示poll操作失败。

*
* A {@code BlockingQueue} may be capacity bounded. At any given
* time it may have a {@code remainingCapacity} beyond which no
* additional elements can be {@code put} without blocking.
* A {@code BlockingQueue} without any intrinsic capacity constraints always
* reports a remaining capacity of {@code Integer.MAX_VALUE}.
*
A BlockingQueue可能是容量有限的。 在任何给定的时间它可能有一个remainingCapacity超过其中没有额外的元素可以put没有阻止。 没有任何内在容量限制的A BlockingQueue总是报告剩余容量为Integer.MAX_VALUE


* {@code BlockingQueue} implementations are designed to be used
* primarily for producer-consumer queues, but additionally support
* the {@link java.util.Collection} interface. So, for example, it is
* possible to remove an arbitrary element from a queue using
* {@code remove(x)}. However, such operations are in general
* <em>not</em> performed very efficiently, and are intended for only
* occasional use, such as when a queued message is cancelled.
*
BlockingQueue实现被设计为主要用于生产者 - 消费者队列,但另外支持Collection接口。 因此,例如,可以使用remove(x)从队列中删除任意元素。 然而,这样的操作通常不能非常有效地执行,并且仅用于偶尔使用,例如当排队的消息被取消时。

* {@code BlockingQueue} implementations are thread-safe. All
* queuing methods achieve their effects atomically using internal
* locks or other forms of concurrency control. However, the
* <em>bulk</em> Collection operations {@code addAll},
* {@code containsAll}, {@code retainAll} and {@code removeAll} are
* <em>not</em> necessarily performed atomically unless specified
* otherwise in an implementation. So it is possible, for example, for
* {@code addAll(c)} to fail (throwing an exception) after adding
* only some of the elements in {@code c}.
*
BlockingQueue实现是线程安全的。 所有排队方法使用内部锁或其他形式的并发控制在原子上实现其效果。 然而, 大量的Collection操作addAll , containsAll , retainAll和removeAll 不一定原子除非在实现中另有规定执行。 因此有可能,例如,为addAll(c)到只增加一些元件在后失败(抛出异常) c 。


* A {@code BlockingQueue} does <em>not</em> intrinsically support
* any kind of &quot;close&quot; or &quot;shutdown&quot; operation to
* indicate that no more items will be added. The needs and usage of
* such features tend to be implementation-dependent. For example, a
* common tactic is for producers to insert special
* <em>end-of-stream</em> or <em>poison</em> objects, that are
* interpreted accordingly when taken by consumers.
*
A BlockingQueue上不支持任何类型的“关闭”或“关闭”操作,表示不再添加项目。 这些功能的需求和使用往往依赖于实现。 例如,一个常见的策略是生产者插入特殊的尾流或毒物 ,这些消费者在被消费者摄取时被相应地解释


*
* Usage example, based on a typical producer-consumer scenario.
* Note that a {@code BlockingQueue} can safely be used with multiple
* producers and multiple consumers.
使用示例,基于典型的生产者 - 消费者场景。 请注意, BlockingQueue可以安全地与多个生产者和多个消费者一起使用。
阅读全文 »

Queue翻译

发表于 2018-11-11 | 分类于 源码
字数统计: 1.7k | 阅读时长 ≈ 8

翻译

类注释
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
A collection designed for holding elements prior to processing.
一个设计用来保存需要预先处理元素的Collection

Besides basic {@link java.util.Collection Collection} operations,
queues provide additional insertion, extraction, and inspection
operations.
除了基本的 Collection操作,队列提供额外的插入、提取和检验操作

Each of these methods exists in two forms: one throws
an exception if the operation fails, the other returns a special
value (either {@code null} or {@code false}, depending on the
operation).

这些方法中存在两种形式:
一个抛出一个异常,如果操作失败,
另一个返回一个特殊的值( null或者 false,根据操作)


The latter form of the insert operation is designed
specifically for use with capacity-restricted {@code Queue}
implementations;

后者的插入操作形式是专门为使用容量限制 Queue实现;

in most implementations, insert operations cannot fail.

在大多数实现,insert操作不能失败。
阅读全文 »

深度解析jdk8-AbstractQueuedSynchronizer的实现分析下

发表于 2018-09-24
字数统计: 4.2k | 阅读时长 ≈ 15

前言

经过本系列的上半部分JDK1.8 AbstractQueuedSynchronizer的实现分析(上)的解读,相信很多读者已经对AbstractQueuedSynchronizer(下文简称AQS)的独占功能了然于胸,
那么这次我们通过对另一个工具类:CountDownLatch的分析来解读AQS的另外一个功能:共享功能。

AQS共享功能的实现

在开始解读AQS的共享功能前,我们再重温一下CountDownLatch,CountDownLatch为java.util.concurrent包下的计数器工具类,
常被用在多线程环境下,它在初始时需要指定一个计数器的大小,然后可被多个线程并发的实现减1操作,并在计数器为0后调用await方法的线程被唤醒,
从而实现多线程间的协作。它在多线程环境下的基本使用方式为:

阅读全文 »

深度解析jdk8-AbstractQueuedSynchronizer的实现分析上

发表于 2018-09-24
字数统计: 4.3k | 阅读时长 ≈ 16

前言

Java中的FutureTask作为可异步执行任务并可获取执行结果而被大家所熟知。通常可以使用future.get()来获取线程的执行结果,在线程执行结束之前,get方法会一直阻塞状态,
直到call()返回,其优点是使用线程异步执行任务的情况下还可以获取到线程的执行结果,但是FutureTask的以上功能却是依靠通过一个叫AbstractQueuedSynchronizer的类来实现,
至少在JDK1.5、JDK1.6版本是这样的(从1.7开始FutureTask已经被其作者Doug Lea修改为不再依赖AbstractQueuedSynchronizer实现了,这是JDK1.7的变化之一)。

阅读全文 »

Hexo+GitHub搭建笔记

发表于 2018-09-20 | 分类于 hexo
字数统计: 644 | 阅读时长 ≈ 3

Node 安装

下载对应版本的Node,直接下一步安装就行,然后检查

1
2
3
4
$ node -v
v10.10.0
$ npm -v
6.4.1

Git 安装

下载对应版本的Git,直接下一步安装就行,然后检查

1
2
$ git --version
git version 2.15.1.windows.2

Hexo 安装

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
$ mkdir hexo
$ cd hexo
$ npm install hexo -g
$ hexo -v
hexo: 3.7.1
hexo-cli: 1.1.0
os: Windows_NT 10.0.17134 win32 x64
http_parser: 2.8.0
node: 10.10.0
v8: 6.8.275.30-node.24
uv: 1.23.0
zlib: 1.2.11
ares: 1.14.0
modules: 64
nghttp2: 1.33.0
napi: 3
openssl: 1.1.0i
icu: 62.1
unicode: 11.0
cldr: 33.1
tz: 2018e


$ hexo s //启动,打开浏览器http://localhost:4000就能看到了
INFO Start processing
INFO Hexo is running at http://localhost:4000 . Press Ctrl+C to stop.
阅读全文 »
air

air

Stay hungry,stay foolish.Keep moving on

6 日志
2 分类
2 标签
RSS
GitHub Gitee E-Mail
© 2018 air | 全站共: 15.6k字 |
由 Hexo 强力驱动
|
主题 — NexT.Mist
0%