http://blog.csdn.net/testcs_dn/article/details/42526549
java線程使用示例——最簡單的線程
線程使用示例一:
- public class ThreadTest {
- public static void main(String[] args) {
- //線程使用示例一:
- new Thread() {
- public void run() {
- while (true) {
- try {
- System.out.println("線程輸出");
- //休眠兩秒
- Thread.sleep(2 * 1000);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
- };
- }.start();
- }
- }
線程使用示例二:
- //線程使用示例二:
- Thread t1 = new Thread(new Runnable(){
- public void run(){
- System.out.println("Mythread 線程t1");
- while(true){
- Singleton3 single3 = Singleton3.getInstance(null);
- System.out.println("線程t1 >> " + single3.toString());
- try {
- Thread.sleep(2000);
- } catch (InterruptedException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- }
- });
- t1.start();