java多线程读书笔记1 多线程中的基本概念词

以上内容均来自于本书和我的自己理解的总结

Java Threads, 3rd Edition [Book] (oreilly.com)

Atomic variables

A set of classes that provide threadsafe operations without synchronization

原子变量

提供线程安全操作而无需同步的一组类

我的理解:利用这种原子变量起到定义线程安全的变量,而且不用额外编写同步代码

Minimal synchronization utilities

Java's new atomic classes provide a means by which developers can, when necessary, write applications that avoid synchronization. This can lead to programs that are highly concurrent.

最小同步实用程序

Java的新原子类类型提供了一种方法,开发者可以在必要时编写避免同步的字样(synchronization)应用程序。这可以使得程序提高更高的并发性

———————————————————————— 

Explicit locks

Synchronization locks that can be acquired and released programmatically

显式锁(精确锁)

可以通过编程方式获取和释放的同步锁

 ———————————————————————— 

Condition variables

Variables that can be the subject of a targeted notification when certain conditions exist

条件变量

存在特定条件时,可能成为目标通知主题的变量

 The Java language has always had the capability to perform data synchronization and thread notification. However, implementation of these features was somewhat limited; you could, for example, synchronize blocks of code or entire methods but synchronizing across methods and classes required extra programming. In J2SE 5.0, explicit locks and condition variables allow you more flexibility when using these features.

Java语言一直能够执行数据同步和线程通知。然而,这些功能的实现有些有限;例如,可以同步代码块或同步整个方法,但跨整个方法和类同步需要额外编程。在J2SE 5.0中,显式锁(精确锁)和条件变量允许您在使用这些特性时具有更大的灵活性。 

————————————————————————

Queues

Collection classes that are thread-aware

队列

线程能够感知并使用的一种集合类

————————————————————————————

Synchronization primitives

New classes that perform complex types of synchronization

同步关键字:

同步原语

执行复杂类型同步的新功能类

 ————————————————————————————

Thread pools

Classes that can manage a pool of threads to run certain tasks

线程池

可以管理一池子线程去执行特定任务们的一种类

  ————————————————————————————

Thread schedulers

Classes that can execute tasks at a particular point in time

线程调度程序

可以在特定时间点执行任务的类

Important thread utilities

At some point in time, virtually all developers who write threaded programs will need to use basic thread utilities such as a pool or a scheduler; many of them will also need to use advanced synchronization primitives. A recognition of this fact is one thing that drove JSR-166—it was certainly possible in previous versions of Java to develop your own thread pools and schedulers. But given the importance of threading in the Java platform, adding these basic utilities greatly increases programmer productivity.

重要的线程实用程序(线程池和时间调度器没有必要自己编写,因为已经有现成的实用程序了)

在某个时候,几乎所有编写线程程序的开发人员都需要使用基本的线程实用程序,比如线程池或调度器;他们中的许多人还需要使用高级同步原语。认识到这一事实是促使JSR-166的原因之一——在Java的早期版本中,开发自己的线程池和调度程序当然是可能的。但是考虑到线程在Java平台中的重要性,添加这些基本实用程序可以极大地提高程序员的工作效率(已经有现成的了,别自己开发,找现成类库即可搞定)。

thread可以有两种创建方式:
第一种 使用Thread class
第二种通过Runnable interface

注意:通过Runnable interface所创建的线程 (通常)需要一个thread的instance,所以我们先从Thread class 开始学起。

创建Thread
生命周期的第一个阶段是Thread的创建。thread是由Thread class的instance来表示,
所以创建thread是通过调用该class的constructor来完成。在我们的范例中使用了最简单的constructor其他 Thread class 的constructor 能够让你指定thread的名称或者
Runnable对象以作为thread的target

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值