package com.vince.thread;admin管理员组文章数量:1636928
import java.util.Date;
/**
* Multi-Thread Implemention
* 1. Extend class thread
* 2. Implement interface Runnable
* @author HarryKuma
*
*/
public class ThreadDemo {
public static void main(String[] args) {
MyThread myThread = new MyThread();
myThread.start();
for (int i = 0; i < 20; i++) {
System.out.println("main-"+i);
}
MyRunnable myRunnable = new MyRunnable();
Thread threadImpleRun = new Thread(myRunnable);
threadImpleRun.start();
}
}
class MyThread extends Thread{
@Override
public void run() {
for (int i = 0; i < 10; i++) {
System.out.println(new Date()+"-"+i);
}
}
}
class MyRunnable implements Runnable{
@Override
public void run() {
for (int i = 0; i < 10; i++) {
System.out.println("MyRunnale-"+i);
}
}
}
本文标签: methodJavaDemothreadMulti
版权声明:本文标题:Demo Java 2 method to implement Multi-Thread 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://m.elefans.com/xitong/1729234358a1191821.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论