java線程用法
阿新 • • 發佈:2017-06-09
method 線程 art oid static stub ner java ring
package com; public class Demo { public static void main(String[] args) { // TODO Auto-generated method stub //方法1 Thread t = new Thread() { public void run() { for (int i = 1; i <= 5; i++) { System.out.print(i+ " "); } } }; t.start(); System.out.print("\r\n"); //方法2 Runnable r = new Runnable() { public void run() { for (int i = 1; i <= 5; i++) { System.out.print(i + " "); } } }; Thread t1= new Thread(r); t1.start(); } }
java線程用法