java实现多线程有两种方式:
线程特征:随机性
一、1.继承Thread类  
   2.覆盖run方法,让多线程执行的程序代码放到run方法中
   3.调用start方法,开启线程
代码实现:
class MyThread extends Thread{
private String name;
public MyThread(){
}
public MyThread(String name){
this.name = name;
}
public void run(){
for(int i = 0;i < 50;i++){
System.out.println(Thread.currentThread().getName()+"--->"+name);
}
}
}
public class TestThread {
public static void main(String[] args) {
MyThread mt1 = new MyThread("first");
MyThread mt2 = new MyThread("second");
mt1.start();
mt2.start();
}
}

二、1.实现Runnable接口,覆盖run方法
   2.通过Thread类建立线程对象,并将实现Runnable接口的子类对象作为参数传递给Thread类的构造方法
   3.调用Thread类的start方法,开启线程
代码实现:
class MyRunnable implements Runnable{
private Integer num = 100;
@Override
public void run() {
while(true){
if(num > 0){
System.out.println(Thread.currentThread().getName()+"--->"+num--);
}
}
}
}
public class TestRunnable {
public static void main(String[] args) {
MyRunnable mr = new MyRunnable();
Thread mr1 = new Thread(mr);
Thread mr2 = new Thread(mr);
Thread mr3 = new Thread(mr);
Thread mr4 = new Thread(mr);
mr1.start();
mr2.start();
mr3.start();
mr4.start();
}
}