package com.haizhitao.thread;
public class ThreadTest2
{
public static void main(String[] args)
{
Thread thread = new Thread(new MyThread());
Thread thread2 = new Thread(new MyThread2());
thread.start();
thread2.start();
}
}
class MyThread implements Runnable
{
@Override
public void run()
{
for(int i = 0; i < 10; i++)
{
System.out.println("hello world: " + i);
}
}
}
class MyThread2 implements Runnable
{
@Override
public void run()
{
for(int i = 0; i < 10; i ++)
{
System.out.println("welcome: " + i);
}
}
}
//output:(每次运行的结果不相同)
// hello world: 0
// hello world: 1
// welcome: 0
// welcome: 1
// welcome: 2
// welcome: 3
// welcome: 4
// hello world: 2
// hello world: 3
// hello world: 4
// hello world: 5
// welcome: 5
// welcome: 6
// welcome: 7
// welcome: 8
// welcome: 9
// hello world: 6
// hello world: 7
// hello world: 8
// hello world: 9
69
最新推荐文章于 2022-12-05 08:30:16 发布