I'm wondering why these little programs won't run in Textpad v5.4.2, whilst it seems to be running seamlessly within Eclipse:
Demo#1
public class MyThread implements Runnable {
String tName;
Thread t;
MyThread (String threadName) {
tName = threadName;
t = new Thread (this, tName);
t.start();
}
public void run() {
try {
System.out.println("Thread: " + tName );
Thread.sleep(2000);
} catch (InterruptedException e ) {
System.out.println("Exception: Thread "
+ tName + " interrupted");
}
System.out.println("Terminating thread: " + tName );
}
}
class MyThreadDemo {
public static void main (String args []) {
new MyThread ("1");
new MyThread ("2");
new MyThread ("3");
new MyThread ("4");
try {
Thread.sleep (10000);
} catch (InterruptedException e) {
System.out.println(
"Exception: Thread main interrupted.");
}
System.out.println(
"Terminating thread: main thread.");
}
}
Demo #2
import java.lang.*;
class SimpleThreadTest
{
public static void main (String... args)
{
new SimpleThread();
System.out.println("Main thread started");
System.out.println("Main thread terminated");
}
}
public class SimpleThread implements Runnable
{
public SimpleThread()
{
t = new Thread(this, "First Thread");
}
public void run()
{
System.out.println("Child thread started.");
System.out.println("Child thread terminated.");
}
private Thread t;
}
/* Sourced and adapted from http://www.devarticles.com/c/a/Java/Mul ... ng-in-Java 03.07.2011 */
Exception in thread "main" java.lang.NoSuchMethodE
Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard