HocKaiMon Entertainment |
Laptop chính hãng + Loa Mini liên hệ Nhân (0937.839.840) |
Latest topics | » Ốc Bụi quan...Nghêu - Sò - Ốc10/5/2015, 5:33 pm by buudiep » 4rum trường THPT Lý Thường Kiệt đây28/11/2012, 12:56 am by johnny_pham2012 » mem mới - Dream ILS - mong pà kon đón nhận ^^24/9/2011, 5:46 pm by dreamils » ngÀy xUi xẺo21/5/2011, 8:10 pm by remember4love » Giới thiệu phim, rạp xem phim thành phố9/3/2011, 6:29 pm by hsvn_bin » website phim, giới thiệu phim8/3/2011, 8:06 pm by hsvn_bin » Nhà hàng, cà phê, shop, đồ cưới, rạp xem phim, ca nhạc, ca kịch22/2/2011, 7:22 pm by hsvn_bin » Tổng hợp địa điểm vui choi, ăn uống thành phố21/2/2011, 5:27 pm by hsvn_bin » Địa chỉ giải trí lí tưởng của bạn27/1/2011, 4:43 pm by hsvn_bin » Dịch vụ ăn uống, giải trí 25/1/2011, 6:46 pm by hsvn_bin |
April 2024 | Mon | Tue | Wed | Thu | Fri | Sat | Sun |
---|
1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | | | | | | Calendar |
|
Thống Kê | Hiện có 5 người đang truy cập Diễn Đàn, gồm: 0 Thành viên, 0 Thành viên ẩn danh và 5 Khách viếng thăm Không Số người truy cập cùng lúc nhiều nhất là 17 người, vào ngày 24/8/2022, 6:52 am |
|
|
Tác giả |
Thông điệp |
Dragon
Admin
|
Tiêu đề: Java - 8/12/09 8/12/2009, 3:02 pm |
|
|
MyThread.java
class MyThread{ public static void main(String[] args){ Thread t; t = Thread.currentThread(); System.out.println("Ten hien tai cua Thread :" +t); t.setName("TTTTT"); t.setPriority(10); System.out.println("Ten moi cua Thread : " +t); System.out.println("Do uu tien cao nhat : "+Thread.MAX_PRIORITY); System.out.println("Do uu tien cao nhat : "+Thread.MIN_PRIORITY); try{ for(int i=1;i<=10;i++){ System.out.println("Gia tri : " +i); Thread.sleep(1000); } } catch(Exception iex){ System.out.println(iex.getMessage()); } } }
ChildThread.java
class ChildThread extends Thread{ Thread t; public ChildThread(){ t = new Thread("Thread con"); System.out.println("Thread con :" +t); } public void run(){ System.out.println("So luong dang hoat dong :" +Thread.activeCount()); try{ for(int i=1;i<=20;i++){ System.out.println("Gia tri Thread con : " +i); Thread.sleep(500); } } catch(InterruptedException e){ System.out.println("Loi tu Thread con"); } System.out.println("Dang thoat Thread con"); } } class MainThread{ public static void main(String[] args){ ChildThread ct = new ChildThread(); ct.start(); Thread th = Thread.currentThread(); try{ System.out.println("Main Thread :" +th); for(int i=1;i<=5;i++){ System.out.println("Gia tri tu main Thread :" +i); Thread.sleep(1000); } } catch(InterruptedException e){ System.out.println("loi tu Thread con"); } System.out.println("Hoan tat !"); } }
MyThread1.java
class ChildThread implements Runnable{ String name; Thread t; ChildThread(String threadname){ name = threadname; t = new Thread(this.name); System.out.println("Thread moi :" +t); t.start(); } public void run(){ System.out.println("So luong dang hoat dong :" +Thread.activeCount()); try{ for(int i=1;i<=5;i++){ System.out.println("Gia tri Thread con : " +i); Thread.sleep(200); } } catch(InterruptedException e){ System.out.println(name + "interrupted."); } System.out.println(name + "Dang thoat."); } } class MainThread1{ public static void main(String[] args){ ChildThread t1 = new ChildThread("T1"); ChildThread t2 = new ChildThread("T2"); ChildThread t3 = new ChildThread("T3"); System.out.println("Thread 1 is alive :"+t1.t.isAlive()); System.out.println("Thread 2 is alive :"+t2.t.isAlive()); System.out.println("Thread 3 is alive :"+t3.t.isAlive()); try{ System.out.println("Main thread cho cac Thread con hoan thanh."); t1.t.join(); t2.t.join(); t3.t.join(); System.out.println("Thread con hoat dong xong"); } catch(InterruptedException e){ System.out.println("Main Thread Interrupted"); } System.out.println("Thread 1 is alive :"+t1.t.isAlive()); System.out.println("Thread 2 is alive :"+t2.t.isAlive()); System.out.println("Thread 3 is alive :"+t3.t.isAlive()); try{ for(int i = 0;i<10;i++){ System.out.println("Main thread : " +i); } } catch(Exception e){ System.out.println("Error"); } System.out.println("Thoat"); } }
|
|
|
|
|
Trang 1 trong tổng số 1 trang |
|
|
Permissions in this forum: |
Bạn không có quyền trả lời bài viết
|
|
|
|
|
|
|