- public class TestThreadDemo {
- public static void main(String args[]) {
- Demo d = new Demo();
- Thread t = new Thread(d);
- t.start();
-
- for(int i=0; i<100; i++) {
- System.out.print(i+" ");
- if(i%10==0) {
- System.out.println();
- }
- }
-
- f.shutdown();
- }
- }
- class Demo implements Runnable {
- boolean flag = true;
-
- public void run() {
- if( flag = true) {
- for(int i =0; i<1000; i++) {
- System.out.print("My Thread is "+i+" ");
- if(i%5==0) {
- System.out.println();
- }
- }
- }
- }
-
- public void shutdown(){
- flag = false;
- }
- }
复制代码 |