• Post Reply Bookmark Topic Watch Topic
  • New Topic

The join program

 
gang meng
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all!
class C extends Thread {
private String name;

private C c;

public C(String name) {
this.name = name;
}

public void setC(C c) {
this.c = c;
}

public void run() {
try {
if (c != null)
c.join();
} catch (Exception e) {
}
for (int i = 0; i < 10; i++) {
try {
sleep(1000);
} catch (Exception e) {
}
System.out.println(name + ":" + i);
}
}
}

public class Test5 {

public static void main(String[] args) {
C c1 = new C("C1");
C c2 = new C("C2");

c1.setC(c2);

c1.start();
c2.start();
try {
c1.join();
c2.join();
} catch (Exception e) {
}
System.out.println("in main()");

}
}

I don`t know the setC`s mean?
please help me?
 
Gerald Mo
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

the public void setC method takes an argument type of 'C' and set the current object's reference 'c' (private C c to be the same as the argument's reference 'c'.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!