Java Notes-8
来源:互联网 发布:利用淘宝双十一赚钱 编辑:程序博客网 时间:2024/05/19 05:03
access by the owner of the lock by allowing only one party to hold the lock at a time
through the lock() and unlock() methods.
-In addition to the standard-looking lock() method, the Lock interface has tryLock()
methods that do not block or that block for a specified period of time in order to acquire
the lock.
-The ReadWriteLock interface is a gateway to two different locks, one for reading and
one for writing. The idea behind read/write locks is that for most resources it is OK for
many “readers” to be viewing data, as long as it is not changing. Conversely, a writer of
the data generally requires exclusive access to it. This is just what read/write locks do.
-. The Condition in‐
terface represents this functionality with its await() , signal() , and signalAll()
methods
-The CountDownLatch is a very simple synchronization utility that allows any number of
threads to block, waiting for a countdown value to reach 0 before being “released” to
continue their activities.
-Semaphores are a very old synchronization construct that has been used in many other
languages. Conceptually, a semaphore is a pool of permits—intangible permission slips
to perform some activity.
-Calling acquire() when no permits are available causes the caller to block
until one is released. In this way, for example, a semaphore could be used to limit access
to some resource to a specified number of threads
-In this code snippet, readData() effectively limits itself to five concurrent reading
threads at any given time.
-The java.util.concurrent.atomic package holds an interesting set of wrapper classes
for atomic, “all-or-nothing” operations on certain primitive types and reference values.
AtomicBoolean.java
AtomicInteger.java
AtomicIntegerArray.java
AtomicLong.java
AtomicLongArray.java
AtomicReference.java
AtomicReferenceArray.java
-The compareAndSet() method first performs a comparison to an expected value
( true or false in the case of a Boolean) and only if the value matches does it assign the
new value. The interesting thing is that both of these operations happen “atomically,”
together.
-The compareAndSet() method has a strange twin named weakCompareAndSet() , which
has the dubious distinction that it simply may not work when called. It is, however, nice
enough to tell you when it doesn’t work by returning false . What’s the point of this?
Well, by allowing this fuzziness, Java may be able to make the implementation of the
weak method much faster than the “certain” one. You can loop and retry the weak
method instead and it may improve performance on some architectures.
-trim() is a useful method that removes leading and trailing whitespace (i.e., carriage
return, newline, and tab) from the String
-In contrast to the immutable string, the java.lang.StringBuilder class is a modifiable
and expandable buffer for characters. You can use it to create a big string efficiently.
StringBuilder and StringBuffer are twins; they have exactly the same API.
- Java Notes-8
- Java Notes-8
- Java - Notes
- notes[java]
- java notes
- java notes
- Java Notes
- Java Notes
- Java 游戏开发Notes
- Java Thread - Notes
- Java 游戏开发Notes
- Java-Notes Documents
- java 访问notes domino
- java 读取notes数据库
- Java Container Learning notes
- Java 游戏开发Notes
- Java Notes: ArrayList
- Notes:java comile flag
- 一个有意思的拼接数组
- Linux定时器
- Nginx如何解决事件过期问题
- Unity3d GUI与NGUI
- Informatica&DAC
- Java Notes-8
- Quick 3.3中display.newColorLayer的错误
- 史上最简单Robotium跨进程操作实践——基于ADB框架
- 排序专题学习笔记——插入排序
- 《数据结构》课程设计
- 课程设计
- Struts2 逐步成长:(三) 文件下载
- 关于java中的非静态代码块和静态代码块
- 为什么静态成员不能访问非静态成员