diff --git a/src/test/java/com/jsh/test/MyRunnable.java b/src/test/java/com/jsh/test/MyRunnable.java new file mode 100644 index 00000000..6b3ede28 --- /dev/null +++ b/src/test/java/com/jsh/test/MyRunnable.java @@ -0,0 +1,9 @@ +package com.jsh.test; + +public class MyRunnable implements Runnable {//实现Runnable接口 + public void run(){ + for(int i=0; i<30; i++){ + System.out.println(Thread.currentThread().getName()+"运行, "+i); //获取当前线程的名称 + } + } +} \ No newline at end of file diff --git a/src/test/java/com/jsh/test/MyThread.java b/src/test/java/com/jsh/test/MyThread.java new file mode 100644 index 00000000..32193875 --- /dev/null +++ b/src/test/java/com/jsh/test/MyThread.java @@ -0,0 +1,10 @@ +package com.jsh.test; + +public class MyThread { + public static void main(String[] args) { + for (int i = 0; i < 3; i++) { + MyRunnable mt = new MyRunnable(); //定义Runnable子类对象 + new Thread(mt, "第" + i + "个线程").start(); + } + } +}