1.继承Thread类
/** * @author Ash * @date: 2016年8月6日 下午10:56:45 * @func: 通过继承Thread类来实现多线程 * @email [email protected] * @Copyright: 2016 Ash. All rights reserved. */ public class ExtendsThread extends Thread{ public static void main(String[] args) { new ExtendsThread().start(); } public void run() { System.out.println("hello"); } }
2.实现Runnable接口
package com.test.thread; public class ImplementsRunable { public static void main(String[] args) { new Thread(new Task()).start(); } } class Task implements Runnable { @Override public void run() { // TODO Auto-generated method stub System.out.println("hello"); } }
时间: 2024-10-05 06:12:39