Java线程:线程的同步与锁
一、同步问题提出
线程的同步是为了防止多个线程访问一个数据对象时,对数据造成的破坏。
例如:两个线程ThreadA、ThreadB都操作同一个对象Foo对象,并修改Foo对象上的数据。
public
class
Foo {
private
int
x = 100;
public
int
getX() {
return
x;
}
public
int
fix(int
y) {
x = x - y;
return
x;
}
}
public
class
MyRunnable implements
Runnable {
private
Foo foo = new
Foo();
public
static
void
main(String[] args) {
MyRunnable r = new
MyRunnable();
Thread ta = new
Thread(r, "Thread-A"
);
Thread tb = new
Thread(r, "Thread-B"
);
ta.start();
tb.start();
}
public
void
run() {
for
(int
i = 0; i < 3; i++) {
this
.fix(30);
try
{
Thread.sleep(1);
} catch
(InterruptedException e) {
e.printStackTrace();
}
&
相关文档:
create PROCEDURE pagelist
@tablename nvarchar(50),
@fieldname nvarchar(50)='*',
@pagesize int output,--每页显示记录条数
@currentpage int output,--第几页
@orderid nvarchar(50),--主键排序
@sort int,--排序方式,1表示升序,0表示降序排列
......
Java NIO API详解
在JDK
1.4以前,Java的IO操作集中在java.io这个包中,是基于流的阻塞(blocking)API。对于大多数应用来说,这样的API使用很方
便,然而,一些对性能要求较高的应用,尤其是服务端应用,往往需要一个更为有效的方式来处理IO。从JDK 1.4起,NIO
API作为一个基于缓冲区,并能提供非阻塞(non-blo ......
public class P {
public static void main(String[] args){
String pattern="000";
java.text.DecimalFormat df = new java.text.DecimalFormat(pattern);
int i = 10,j=6;
System.out.println("i="+df.format(i)+"\nj="+df.format(j));
}
}
---------------------输出-----------------------
i=010 ......
java学习:彻底明白Java的IO系统
文章来源:互联网
一. Input和Output
1. stream代表的是任何有能力产出数据的数据源,或是任何有能力接收数据的接收源。在Java的IO中,所有的stream(包括Input和Out stream)都包括两种类型:
1.1 以字节为导向的stream
以字节为导向的stream,表示以字节为单位从stream中读取或往st ......
java 代码实现
public static boolean isLetter(char c) {
int k = 0x80;
return c / k == 0 ? true : false;& ......