您的位置:首页 > 运维架构 > Linux

centos上安装autoconf-2.69

2013-12-28 10:33 381 查看
package com;
public class TraditionalThreadSynchronizeTest {
public static void main(String[] args) {
new TraditionalThreadSynchronizeTest().init();
}
public void init() {
final Output output = new Output();
new Thread(new Runnable() {
@Override
public void run() {
while (true) {
try {
Thread.sleep(10);
} catch (InterruptedException e) {
e.printStackTrace();
}
output.output("zhangxiaoxiang");
}
}
}).start();
new Thread(new Runnable() {
@Override
public void run() {
while (true) {
try {
Thread.sleep(10);
} catch (InterruptedException e) {
e.printStackTrace();
}
output.output2("lihuoming");
}
}
}) .start();

new Thread(new Runnable() {
@Override
public void run() {
while (true) {
try {
Thread.sleep(10);
} catch (InterruptedException e) {
e.printStackTrace();
}
output.output3("lihuoming");
}
}
}) .start();
}
static class Output {
public void output(String name) {
int len = name.length();
synchronized (Output.class) {
//synchronized (this) {
for (int i = 0; i < len; i++) {
System.out.print(name.charAt(i));
}
System.out.println();
}
}

public synchronized void output2(String name) {
int len = name.length();
//          synchronized (Output.class) {
//synchronized (this) {
for (int i = 0; i < len; i++) {
System.out.print(name.charAt(i));
//}
System.out.println();
}
}

public static synchronized void output3(String name) {
int len = name.length();
//          synchronized (Output.class) {
//synchronized (this) {
for (int i = 0; i < len; i++) {
System.out.print(name.charAt(i));
//}
System.out.println();
}
}
}
}



本文出自 “狐灵传说” 博客,请务必保留此出处http://foxspark.blog.51cto.com/6273668/1275847
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: