java基础练习之多线程接口实现(1)

//通过实现Runnable接口实现多线程
public class Runnable1 implements Runnable{
 int k=0;
 public Runnable1(int k){
  this.k=k;
 }
 public void run(){
  int i=k;
  while(i<50){
   System.out.println(i+" ");
   i+=2;
  }
 }
 public static void main(String args[]){
  Runnable1 r1=new Runnable1(1);
  Runnable1 r2=new Runnable1(2);
  Thread t1=new Thread(r1);
  Thread t2=new Thread(r2);
  t1.start();
  t2.start();
  for(int i=0;i<40;i++)System.out.println("A");
 }
}

你可能感兴趣的:(java基础练习)