Would you like to react to this message? Create an account in a few clicks or log in to continue.

ҧ Start Run ҧѹѧ

 :: ¹ҡѹ :: ѡѺ Threads

Go down

ҧ Start  Run ҧѹѧ Empty ҧ Start Run ҧѹѧ

ตั้งหัวข้อ  Admin Fri May 23, 2008 1:17 am

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");
}
}


แก้ไขล่าสุดโดย Admin เมื่อ Fri May 23, 2008 1:19 am, ทั้งหมด 1 ครั้ง
Admin
Admin
Admin

จำนวนข้อความ : 112
Registration date : 18/05/2008

http://chawban.chocoforum.com

ขึ้นไปข้างบน Go down

ҧ Start  Run ҧѹѧ Empty Re: ҧ Start Run ҧѹѧ

ตั้งหัวข้อ  Admin Fri May 23, 2008 1:18 am

Main1
A 0
Main2
B 0
A 1
B 1
A 2
B 2

ѧࡵ ѹоҺ÷Ѵҧ͡ҡ͹
Admin
Admin
Admin

จำนวนข้อความ : 112
Registration date : 18/05/2008

http://chawban.chocoforum.com

ขึ้นไปข้างบน Go down

ҧ Start  Run ҧѹѧ Empty Re: ҧ Start Run ҧѹѧ

ตั้งหัวข้อ  Admin Fri May 23, 2008 1:20 am

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
Admin
Admin
Admin

จำนวนข้อความ : 112
Registration date : 18/05/2008

http://chawban.chocoforum.com

ขึ้นไปข้างบน Go down

ขึ้นไปข้างบน

- Similar topics

 :: ¹ҡѹ :: ѡѺ Threads

 
Permissions in this forum:
คุณไม่สามารถพิมพ์ตอบ