Java 简单多线程

一、主类

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class ThreadDemo {
    public static void main(String[] args) throws Exception {
        log.info("this is main");

        TestThread thread = new TestThread();
        thread.start();

        Thread runable = new Thread(new TestRunable());
        runable.start();

        log.info("this is main too.");
    }
}

二、多线程Thread

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class TestThread extends Thread{

    @Override
    public void run() {
        log.info("this is thread.");
    }

}

三、多线程Runable

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class TestRunable implements Runnable{
    @Override
    public void run() {
        log.info("this is runable");
    }
}

 

posted @ 2025-03-12 15:19  都是城市惹的祸  阅读(3)  评论(0)    收藏  举报