ҧ Start Run ҧѹѧ
:: ¹ҡѹ :: ѡѺ Threads
หน้า 1 จาก 1
ҧ Start Run ҧѹѧ
package threads;
public class Sample implements Runnable {
String name;
public Sample(String name) {
this.name = name;
}
public void run() {
for(int i = 0; i < 3; ++i) {
System.out.println(name+" "+i);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
public static void main(String[] args) {
Thread t = new Thread(new Sample("A"));
Thread t1 = new Thread(new Sample("B"));
t.start();
System.out.println("Main1");
t1.start();
System.out.println("Main2");
}
}
public class Sample implements Runnable {
String name;
public Sample(String name) {
this.name = name;
}
public void run() {
for(int i = 0; i < 3; ++i) {
System.out.println(name+" "+i);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
public static void main(String[] args) {
Thread t = new Thread(new Sample("A"));
Thread t1 = new Thread(new Sample("B"));
t.start();
System.out.println("Main1");
t1.start();
System.out.println("Main2");
}
}
แก้ไขล่าสุดโดย Admin เมื่อ Fri May 23, 2008 1:19 am, ทั้งหมด 1 ครั้ง
Re: ҧ Start Run ҧѹѧ
package threads;
public class Sample implements Runnable {
String name;
public Sample(String name) {
this.name = name;
}
public void run() {
for(int i = 0; i < 3; ++i) {
System.out.println(name+" "+i);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
public static void main(String[] args) {
Thread t = new Thread(new Sample("A"));
Thread t1 = new Thread(new Sample("B"));
t.run();
System.out.println("Main1");
t1.run();
System.out.println("Main2");
}
}
A 0
A 1
A 2
Main1
B 0
B 1
B 2
Main2
public class Sample implements Runnable {
String name;
public Sample(String name) {
this.name = name;
}
public void run() {
for(int i = 0; i < 3; ++i) {
System.out.println(name+" "+i);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
public static void main(String[] args) {
Thread t = new Thread(new Sample("A"));
Thread t1 = new Thread(new Sample("B"));
t.run();
System.out.println("Main1");
t1.run();
System.out.println("Main2");
}
}
A 0
A 1
A 2
Main1
B 0
B 1
B 2
Main2
Similar topics
» ??????ҧ????? Enum
» ??????ҧ Hello World
» ??????ҧ??????ҧ GUI ???? Swing
» ??????ҧ????? Generic (???????? array ??Ѻ)
» ǧ?ê??Ե?ͧ applet ???? 4 ??ǧ??? init() start() stop() ??? destroy()
» ??????ҧ Hello World
» ??????ҧ??????ҧ GUI ???? Swing
» ??????ҧ????? Generic (???????? array ??Ѻ)
» ǧ?ê??Ե?ͧ applet ???? 4 ??ǧ??? init() start() stop() ??? destroy()
:: ¹ҡѹ :: ѡѺ Threads
หน้า 1 จาก 1
Permissions in this forum:
คุณไม่สามารถพิมพ์ตอบ