关于线程学习打的代码 //by EditPlus
class ThreadTest extends Thread
{
public void run()
{
System.out.println("the thread is running!");
}
public void run(String s)
{
System.out.println("thethread is :" + s);
}
public static void main(String[] args)
{
ThreadTest threadTest1 = new ThreadTest();
Thread thread1 = new Thread(threadTest1);
thread1.start();
for(int i = 0; i <= 1100; i++);
//when you write the i++,you should not write it like this:i ++..there is no space between the i and the ++!!be careful!
threadTest1.run("wo ai ni babe!");
}
}
public class PingPong extends Thread
{
private String word;
private int delay;
public PingPong(String s,int i)
{
word = s;
delay = i;
}
public void run()
{
try
{
for( int i = 1; i <= 100; i++)
{
System.out.println(word + "is what i want!");
Thread.sleep(delay);
}
}
catch(InterruptedException e)
{
return;
}
}
public static void main(String argv[])
{
new PingPong("wo",30).start();
new PingPong("wod",100).start();
}
}
public class ThreadTest1 implements Runnable
{
public ThreadTest1()
{
System.out.print("babe!");
}
public ThreadTest1(String s)
{
System.out.print("BABE " + s);
}
public void run()
{
System.out.println("what I want is your heart and your body!");
}
public static void main(String[] args)
{
ThreadTest1 th = new ThreadTest1();
Thread thread = new Thread(th);
ThreadTest1 th1 = new ThreadTest1("Wjf");
Thread thread1 = new Thread(th1);
thread.start();
thread1.start();
}
}
芳儿宝贝.我爱你