---
title: "传统多线程的创建方法"
author: "youyang_java"
date: "2014-04-21T16:00:56Z"
tags: []
categories: ["编程语言"]
slug: "untitled"
draft: false
lastmod: "2014-04-21T16:00:56Z"
id: 2051351
url: "https://youyang-java.iteye.com/blog/2051351"
---

![](http://dl2.iteye.com/upload/attachment/0096/3355/51e1827a-0e0a-30dc-943b-4788935f713f.png)  
 

    /\**  
     * @param 传统的线程的两张创建方法  
     \*/  
    public static void main(String\[] args) {  
         
        Thread thread = new Thread() {  
             
            @Override  
            public void run() {  
                 
                while (true) {  
                    try {  
                        Thread.sleep(500);  
                    } catch (InterruptedException e) {  
                        e.printStackTrace();  
                    }  
                    System.out.println("1:" + Thread.currentThread().getName());  
                }  
            }  
        };  
         
        thread.start();  
         
        Thread thread2 = new Thread(new Runnable() {  
             
            @Override  
            public void run() {  
                 
                while (true) {  
                    try {  
                        Thread.sleep(500);  
                    } catch (InterruptedException e) {  
                        e.printStackTrace();  
                    }  
                    System.out.println("2:" + Thread.currentThread().getName());  
                }  
            }  
             
        });  
         
        thread2.start();  
    }

 

     /\**  
     * @param 传统定时器  
     \*/  
    public static void main(String\[] args) {  
         
        new Timer().schedule(new TimerTask(){

            @Override  
            public void run() {  
                System.out.println("执行...");  
                 
            }  
             
        }, 3000, 1000);//第一次执行在3秒后，后面就每隔1秒执行一次

    }