Java theory and practice
1. Multiply-Thread
Locks offer two primary features: mutual exclusion and visibility. Mutual exclusion means only one thread at a time may hold a given lock, so only one thread at a time will be using the shared data. Visibility is to ensure that changes made to shared data prior to releasing a lock are made visible to another thread that subsequently acquires that lock
you must ensure that your threads spend most of their time actually doing work, rather than waiting for more work to do, or waiting for locks on shared data structures
An algorithm is said to be wait-free if every thread will continue to make progress in the face of
arbitrary delay (or even failure) of other threads. By contrast, a lock-free algorithm requires only that some thread always make progress. (Another way of defining wait-free is that each thread is guaranteed to correctly compute its operations in a bounded number of its own steps, regardless of the actions, timing, interleaving, or speed of the other threads. This bound may be a function of the number of threads in the system; for example, if ten threads each execute the CasCounter.increment() operation once, in the worst case each thread will have to retry at most nine times before the increment is complete.)
A common technique for tuning the scalability of a concurrent application that is experiencing contention is to reduce the granularity of the lock objects used, in the hopes that more lock acquisitions will go from contended to un-contended. The conversion from locking to atomic variables achieves the same end -- by switching to a finer-grained coordination mechanism, fewer operations become contended, improving throughput.
1.0 Thread
1.1 synchronized/wait.notify
1.2 volatile
Due to the semantics of some programming languages, the code generated by the compiler is allowed to update the shared variable to point to a partially constructed object before A has fini
相关文档:
命名规范
定义这个规范的目的是让项目中所有的文档都看起来像一个人写的,增加可读性,减少项目组中因为换人而带来的损失。(这些规范并不是一定要绝对遵守,但是一定要让程序有良好的可读性)
Package 的命名
Package 的名字应该都是由一个小写单词组成。
Class 的命名
Class 的名字必须 ......
最近一段时间对java感上了兴趣,因为借了一本《Thinking in java》,一直没时间看,快到还书的时候了,书总不能白借吧。看了两天,大概是扫了100多页吧。准备编写第一个java程序。
从网上查资料,需要JDK,于是下载,安装。具体设置如下:
第 ......
JAVA Socket超时浅析
套接字或插座(socket)是一种软件形式的抽象,用于表达两台机器间一个连接的“终端”。针对一个特定的连接,每台机器上都有一个“套接字”,可以想象它们之间有一条虚拟的“线缆”。JAVA有两个基于数据流的套接字类:ServerSocket,服务器用它“侦听&rdquo ......
<!--
@page { margin: 0.79in }
P { margin-bottom: 0.08in }
-->
Java中的
io
我对流的理解是:源到目的地的轨迹,所以流的一端是数据源(输入流)或者接收器(输出流),另一端是
io中的某个类;这里说明下,
Scanne ......