日期:2014-05-20 浏览次数:20642 次
public class TraditionalThreadSynchronized {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
new TraditionalThreadSynchronized().init();
}
private void init(){
/**内部类不能访问局部变量,所以这里要用final*/
final Outputer outputer = new Outputer();
new Thread(new Runnable() {
@Override
public void run() {
while(true){
try {
Thread.sleep(5);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
outputer.output("GavinlinHere");
}
}
}).start();
new Thread(new Runnable() {
@Override
public void run() {
while(true){
try {
Thread.sleep(5);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();