Extending the Thread class

i would like to do that

1) One thread displays "ABC" every 2 second;

2) The other thread displays DEF every 5 seconds;

i need to create the threads by extending the Thread class ...

thank you for your help ,

publicclass Thread1extends Thread{

public Thread1(String s ){

super (s);

}

publicvoid run(){

for (int i=0; i<5; i++ ){

System.out.println(getName());

try{

sleep ((long) 5000);

}catch (InterruptedException e ){

/* do nothing */

}

}

}

publicstaticvoid main (String args[]){

new Thread1 ("ABC").start();

new Thread1 ("DEF").start();

}

}

[1712 byte] By [benjaminCcca] at [2007-11-26 21:56:01]
# 1
Why extend Thread when you can just implement Runnable?
DrLaszloJamfa at 2007-7-10 3:52:15 > top of Java-index,Java Essentials,Java Programming...
# 2
prolly cuz its homework and he wants us to do it for him.
maple_shafta at 2007-7-10 3:52:15 > top of Java-index,Java Essentials,Java Programming...
# 3
> thank you for your help ,You didn't ask a question.
jschella at 2007-7-10 3:52:15 > top of Java-index,Java Essentials,Java Programming...
# 4
Yes, you need to use one of these: "?"
DrLaszloJamfa at 2007-7-10 3:52:15 > top of Java-index,Java Essentials,Java Programming...
# 5
> need to create the threads by extending the Thread class ...Must be homework. Teachers seem to delight in forcing students to use bad practices that they then have to unlearn after graduation.
DrClapa at 2007-7-10 3:52:15 > top of Java-index,Java Essentials,Java Programming...
# 6

Holy F*cking Sh|t.

If I had known you had started another thread (no pun intended).

DOUBLE POST:

http://forum.java.sun.com/thread.jspa?threadID=5149365

public class RepeatThread implements Runnable{

public static void main (String args[]) {

Thread t1 = new Thread(new RepeatThread(1000), "ABC");

t1.start();

Thread t2 = new Thread(new RepeatThread(3000), "DEF");

t2.start();

}

public RepeatThread(int delay){

this.delay = delay;

}

public void run(){

try{

while(true){

System.out.println(Thread.currentThread().getName());

Thread.sleep(delay);

}

} catch(Exception e){}

}

int delay;

}

TuringPesta at 2007-7-10 3:52:15 > top of Java-index,Java Essentials,Java Programming...