/** * Create 3 threads, each an Echo object */ public class MainThread { public static void main( String[] args ) { // Create the tasks Echo e1 = new Echo( 'A', 20 ); Echo e2 = new Echo( 'B', 20 ); Echo e3 = new Echo( 'C', 20 ); // Create the Thread objects Thread t1 = new Thread( e1 ); Thread t2 = new Thread( e2 ); Thread t3 = new Thread( e3 ); // Every thread has a priority, which is inherited from its parent // (typically 1-10) System.out.println( "Priority of t3 is " + t3.getPriority() ); t3.setPriority( Thread.MAX_PRIORITY ); System.out.println( "Priority of t3 is now " + t3.getPriority() ); // JVM picks the currently runnable thread with the highest priority // (equal priority threads are executed round-robin) // A lower-priority thread can only run when no higher-priority // threads are running or runnable // Start the threads t1.start(); // start() creates the thread, then t2.start(); // calls the run() method... t3.start(); } }