四種方式 sychronized關鍵字
sychronized method(){}
sychronized (objectReference) {/*block*/}
static synchronized method(){}
sychronized(classname
其中
要注意的是sychronized method()不是鎖這個函數
還有
class MyLock
{
synchronized getLock()
{
//####還沒寫完
}
}
五個等級 參見effective java Item
immutable 不可變對象
thread
conditionally thread
thread
thread
wait & notifyAll
在循環中使用wait 使用notifyAll而不是notify
pipe
java中也有pipe的
/* set up pipes */
PipedOutputStream pout
PipedInputStream pin
PipedOutputStream pout
PipedInputStream pin
/* construct threads */
Producer prod = new Producer(pout
Filter filt = new Filter(pin
Consumer cons = new Consumer(pin
/* start threads */
prod
From:http://tw.wingwit.com/Article/program/Java/gj/201311/27306.html