package com.sl.java.test.atm;
import java.lang.Thread;
public class MyThread extends Thread{
private String name;
public MyThread(String name){
this.name=name;
}
public void run(){
for(int i=0;i<10;i++){
System.out.println(name+"运行,1="+i);
}
}
}
package com.sl.java.test.atm;
public class Thread {
public static void main(String[] args) {
MyThread m=new MyThread("线程A");
MyThread m1=new MyThread("线程B");
m.run();
m1.run();
}
}
------解决方案--------------------
多线程调用的是start方法,不是run方法,哥哥。
------解决方案--------------------
class MyThread extends Thread
{
private String name;
public MyThread( String name )
{
this.name = name;
}
public void run( )
{
for ( int i = 0; i < 10; i++ )
{
System.out.println( name + "运行,1=" + i );
}
}
}
public class Test
{
public static void main( String[] args )
{
MyThread m = new MyThread( "线程A" );
MyThread m1 = new MyThread( "线程B" );
m.start( );
m1.start( );
}
}
我跑了下很正常。
------解决方案--------------------
- Java code
package com.sl.java.test.atm; //"l"与"1"需要区别,尽量避免使用(不易区分);另外包名写的也太长了,呵呵import java.lang.Thread; //对于java.lang包中的类,不需要进行导入,public class MyThread extends Thread{ private String name; public MyThread(String name) { this.name=name; } public void run() { for(int i=0;i<10;i++) { System.out.println(name+"运行,1="+i); } }}