请兄弟们帮忙说说这每一行代码都是什么意思?public class ThreadDemo3
{
public static void main(String args[])
{
//new TestThread ().start();
TestThread tt=new TestThread();
Thread t=new Thread(tt);
t.start();
{
System.out.println("main threan is running");
}
}
}
class TestThread implements Runnable //extends Thread
{
public void run()
{
while(true)
{
System.out.println(Thread.currentThread().getName()+
"is running");
}
}
}
{
public static void main(String args[])
{
//new TestThread ().start();
TestThread tt=new TestThread();
Thread t=new Thread(tt);
t.start();
{
System.out.println("main threan is running");
}
}
}
class TestThread implements Runnable //extends Thread
{
public void run()
{
while(true)
{
System.out.println(Thread.currentThread().getName()+
"is running");
}
}
}
package com.test;/**
*
* @author botao ThreadDemo3 只是一个测试类而已. 其中通过线程的不同实现方式,进行不同的初始化.
*/
public class ThreadDemo3 {
public static void main(String args[]) {
// new TestThread ().start();
Thread t1 = new Thread(new TestThread());// 创建线程1,这中方式创建好象是通过代理的设计模式来实现多线程的.
t1.start();// 开启线程
Thread t2 = new TestThread2();// 创建线程2
t2.start();// 开启线程
// 主现成的任务
for (int i = 0; i < 100; i++) {
System.out.println("主要的" + "is running");
}
}
}class TestThread implements Runnable {// 实现多现成的第一种方式,实现Runnable接口,实现run方法
/**
* run中写要做的事.
*/
public void run() {
for (int i = 0; i < 100; i++) {
System.out.println("次要一一一一一一一一一一一一一" + "is running");
}
}
}class TestThread2 extends Thread {// 实现多现成的第二种方式,继承Thread,重写run方法. /**
* run中写要做的事.
*/
public void run() {
for (int i = 0; i < 100; i++) {
System.out.println("次要二二二二二二二二二二二二二二二二二二二二二二二二二二二二二二二二二二二"
+ "is running");
}
}}
基本上没什么可讲的,不知道对lz有用没??
public Thread(Runnable target)
Allocates a new Thread object. This constructor has the same effect as Thread(null, target, gname), where gname is a newly generated name. Automatically generated names are of the form "Thread-"+n, where n is an integer. 启动后运行的就是target的run方法
很感谢谢LZ,给我学习JAVA有很大的鼓励