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"); } }
有些事情,没经历过不知道原理,没失败过不明白奥妙,没痛苦过不了解真谛。临渊羡鱼,不如退而结网!

浙公网安备 33010602011771号