标签:rgba print rri runable main span sys pre world
public class ThreadCreateDemo1 { public static void main(String[] args) { MyThread thread = new MyThread(); thread.start(); //该方法调用多次,出现IllegalThreadStateException } } class MyThread extends Thread { @Override public void run() { super.run(); System.out.println("hellow_world!"); } }
public class ThreadCreateDemo2 { public static void main(String[] args) { Runnable runnable = new MyRunnable(); Thread thread = new Thread(runnable); thread.start(); } } class MyRunnable implements Runnable { public void run() { System.out.println("通过Runnable创建的线程!"); } }
线程运行结果与执行顺序无关
线程的调度是由CPU决定,CPU执行子任务时间具有不确定性。
标签:rgba print rri runable main span sys pre world
原文地址:https://www.cnblogs.com/ohayo/p/14816371.html