博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Java多线程学习笔记-线程的使用
阅读量:4651 次
发布时间:2019-06-09

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

Java中创建多线程的三种方法

1、继承Thread类创建线程

2、实现Runnable接口创建线程

3、使用Callable和Future创建线程

------------------------------------------------------------------------------------------------分割线---------------------------------------------------------------------------------------------------------------------------------------------------------------------------

一、继承Thread类创建线程

/** * @ Author     :ZhuZhu * @ Date       :Created in 16:54 2019/6/9 * @ Description: */public class MyThread extends Thread {    // 重写run方法    public void run(){        for (int i = 1;i <= 5;i++){            System.out.println("Thread :"+i);        }    }}
public class Test1 {
public static void main(String[] args) throws InterruptedException {
MyThread thread = new MyThread(); thread.start(); } }
 

打印结果:

------------------------------------------------------------------------------------------------分割线---------------------------------------------------------------------------------------------------------------------------------------------------------------------------

转载于:https://www.cnblogs.com/ldh666/p/11012666.html

你可能感兴趣的文章