首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 企业软件 > 行业软件 >

线程范例2

2012-07-02 
线程实例2public class threadDemo1 extends Thread {int flagpublic threadDemo1(String name, int f) {

线程实例2
public class threadDemo1 extends Thread {
int flag;
public threadDemo1(String name, int f) {
super(name);
this.flag = f;
}

public void run() {
char ch;
System.out.println();
System.out.print(getName() + " start: ");
synchronized ("ss") {
if (flag == 0) {

for (ch = 'a'; ch <= 'z'; ch++)
System.out.print(ch + " ");
}

else if (flag == 1) {
for (ch = 'A'; ch <= 'Z'; ch++)
System.out.print(ch + " ");
}
System.out.print(getName() + " end!");
}
}

public static void main(String[] args) {
threadDemo t1 = new threadDemo("线程1", 1);
threadDemo t2 = new threadDemo("线程2", 0);
// System.out.println("active: "+Thread.activeCount());
t1.start();
t2.start();
System.out.println("active: " + Thread.activeCount());
}
}

热点排行