Java多线程

xiaoxiao2021-02-28  124

1.实现runnable接口实现功能性解耦

 

package com.test.thread; public class TestRunnable implements Runnable{ @Override public void run() { for (int i = 0; i < 20; i++) { System.out.println(Thread.currentThread().getName()); } } } package com.test.thread; public class TestMain { public static void main(String[] args) { TestRunnable runnable_01=new TestRunnable(); Thread thread=new Thread(runnable_01, "runnable_01"); TestRunnable runnable_02=new TestRunnable(); Thread thread2=new Thread(runnable_02, "runnable_02"); thread.start(); thread2.start(); } }

 

 

 

 

 

转载请注明原文地址: https://www.6miu.com/read-69828.html

最新回复(0)