public class PrintThread6 extends Thread { String message; public PrintThread6 (String m) { message = m; } public void run () { for (int i = 0; i<10000; i++) { // /* try { Thread.sleep(1); } catch(InterruptedException e) { System.out.println("Thread interrupted in sleep"); } // */ System.out.print(message); } } public static void main (String args[ ]) { try { Thread.sleep(0); } catch(InterruptedException e) { System.out.println("Main interrupted before creating threads"); } Thread a = new PrintThread6("a"); Thread b = new PrintThread6("b"); Thread c = new PrintThread6("c"); Thread d = new PrintThread6("d"); Thread e = new PrintThread6("e"); Thread f = new PrintThread6("f"); Thread g = new PrintThread6("g"); Thread h = new PrintThread6("h"); Thread i = new PrintThread6("i"); Thread j = new PrintThread6("j"); Thread k = new PrintThread6("k"); Thread l = new PrintThread6("l"); Thread m = new PrintThread6("m"); Thread n = new PrintThread6("n"); Thread o = new PrintThread6("o"); Thread p = new PrintThread6("p"); Thread q = new PrintThread6("q"); Thread r = new PrintThread6("r"); Thread s = new PrintThread6("s"); Thread t = new PrintThread6("t"); Thread u = new PrintThread6("u"); Thread v = new PrintThread6("v"); Thread w = new PrintThread6("w"); Thread x = new PrintThread6("x"); Thread y = new PrintThread6("y"); Thread z = new PrintThread6("z"); a.setPriority(3); b.setPriority(7); System.out.println("Priority of main thread: " + Thread.currentThread().getPriority() + ", thread a: " + a.getPriority() + ", thread b: " + b.getPriority()); a.start(); b.start(); c.start(); d.start(); e.start(); f.start(); g.start(); h.start(); i.start(); j.start(); k.start(); l.start(); m.start(); n.start(); o.start(); p.start(); q.start(); r.start(); s.start(); t.start(); u.start(); v.start(); w.start(); x.start(); y.start(); z.start(); int active = Thread.activeCount(); System.out.print("c"); try { a.join(); b.join(); c.join(); d.join(); e.join(); f.join(); g.join(); h.join(); i.join(); j.join(); k.join(); l.join(); m.join(); n.join(); o.join(); p.join(); q.join(); r.join(); s.join(); t.join(); u.join(); v.join(); w.join(); x.join(); y.join(); z.join(); } catch (InterruptedException ie) { System.out.println("Main interrupted whilst joining threads"); } System.out.println("c"); System.out.println("\nActive threads: " + active); } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)