java例程练习(多线程[yield()方法])

摘要: public class Test { public static void main(String[] args) { MyThread m1 = new MyThread("m1"); MyThread m2 = new MyThread("m2"); m1.start(); m2.start(); } } class MyThread extends Thread { MyThread(String s) { super(s); } public void run() { for(int i = 1; i <= 100; i++) { Sys 阅读全文
posted @ 2012-05-04 23:26 spring学习笔记 阅读(174) 评论(0) 推荐(0)

java例程练习(多线程[join()方法])

摘要: public class Test { public static void main(String[] args) { MyThread myThread = new MyThread("m1"); myThread.start(); //产生分支,子线程开始执行 try{ myThread.join();//------等待合并myThread子线程,主线程才开始执行 } catch(InterruptedException e) {} for(int i = 1; i <= 10; i++) { System.out.println("I... 阅读全文
posted @ 2012-05-04 23:15 spring学习笔记 阅读(159) 评论(0) 推荐(0)

java例程练习(多线程[sleep()方法])

摘要: import java.util.*; public class Test { public static void main(String[] args) { MyThread thread = new MyThread(); thread.start(); try { Thread.sleep(10000);//主线程睡眠 } catch(InterruptedException e) { } thread.interrupt(); //-----------不是最好的方法 //thread.flag = false; ... 阅读全文
posted @ 2012-05-04 23:01 spring学习笔记 阅读(247) 评论(0) 推荐(0)

java例程练习(多线程的两种创建方式)

摘要: //接口------推荐 public class Test { public static void main(String[] args) { Runner1 r = new Runner1(); //r.run();------->不是多线程,只是方法调用 Thread t = new Thread(r); t.start();//必须调用线程类的start()方法 //也可以这样: //new Thread(new Runner1()).start(); for(int i = 0; i < 100; i++) { ... 阅读全文
posted @ 2012-05-04 22:26 spring学习笔记 阅读(181) 评论(0) 推荐(0)

java例程练习(对象流)

摘要: import java.io.*; // transient 关键字 // serializable 接口 // externalizable 接口 public class Test { public static void main(String[] args) throws Exception{ T t = new T(); t.k = 8; FileOutputStream fos = new FileOutputStream("C:/java/testobjectio.txt"); ObjectOutputStream oos = new Obj... 阅读全文
posted @ 2012-05-04 17:31 spring学习笔记 阅读(165) 评论(0) 推荐(0)