Java Swing Layout Manager Event Handling Inner Classes Swing Applet Exceptions Threads![]() Multitasking & Multithreading![]() What is a Thread![]() Sequential Flow of Control![]() Life Cycle of a Thread![]() Subclassing Thread![]() Controlling Thread![]() Implementating Runnable![]() When to Use the Runnable Interface![]() Multithreading Example![]() Pre-emptive Scheduling![]() Synchronization (Consumer/Producer)![]() The Producer![]() The Consumer![]() Testing![]() Mutual Exclusion ![]() Exercise![]() Deadlock Java I/O Network Programming Resources | Subclassing Threadpublic class SimpleThread extends Thread {
public SimpleThread(String str) {
super(str);
}
public void run() {
for (int i = 0; i < 10; i++) {
System.out.println(i + " " + getName());
try {778
sleep((long)(Math.random() * 1000));
} catch (InterruptedException e) {}
}
System.out.println("DONE! " + getName());
}
}public class TwoThreadsDemo {
public static void main (String[] args) {
new SimpleThread("Jamaica").start();
new SimpleThread("Fiji").start();
}
} |