博客
关于我
Java多线程01
阅读量:324 次
发布时间:2019-03-04

本文共 853 字,大约阅读时间需要 2 分钟。

方法1

package cn.sxt.TestT;/** * 声明一个Thread的子类 * 重写run方法 * 对象调用start方法 * @author 佳哥 * */public class SonThread extends Thread{   	//重写run方法	public void run()	{   		for(int i = 0; i<10; i ++)		{   			System.out.println("跑啊 +" + i);		}	}	public static void main(String[] args) {   	SonThread st = new SonThread();	st.start();	for(int i = 0; i<10; i ++)	{   		System.out.println("主方法啊"+i);	}}}

方法2

package cn.sxt.TestT;/** * 声明一个类实现Runnable接口 * 重写run方法 * 但需要和方法1一样需要掉用调用start方法来启动线程,所以需要创建一个thread对象 * @author 佳哥 * */public class ImplementsThread implements Runnable{   	//重写run方法	public void run()	{   		for(int i = 0; i<10; i ++)		{   			System.out.println("跑啊 +" + i);		}	}	public static void main(String[] args) {   	ImplementsThread it = new ImplementsThread();	new Thread(it).start();		for(int i = 0; i<10; i ++)	{   		System.out.println("主方法啊"+i);	}}}

转载地址:http://lgeq.baihongyu.com/

你可能感兴趣的文章
MySQL之2003-Can‘t connect to MySQL server on ‘localhost‘(10038)的解决办法
查看>>
MySQL之CRUD
查看>>
MySQL之DML
查看>>
Mysql之IN 和 Exists 用法
查看>>
MYSQL之REPLACE INTO和INSERT … ON DUPLICATE KEY UPDATE用法
查看>>
MySQL之SQL语句优化步骤
查看>>
MYSQL之union和order by分析([Err] 1221 - Incorrect usage of UNION and ORDER BY)
查看>>
Mysql之主从复制
查看>>
MySQL之函数
查看>>