/** * how to create a thread, version 4 * @author mh, inspired by [Oechsle 2018] * */ class MyThread extends Thread { // pattern of behaviour private String name; final int MAX = 10; public MyThread (String name) { this.name = name; } // constructor public void run() { // the actual code to be executed for (int i = 0; i process b.start(); // c.start(); try { b.join(); // Wait for this thread to end a.join(); // c.join(); } catch (Exception e) {} System.out.println(" -- end of ThreadDemo4 -- "); } // main } // class ThreadDemo1 class Simulate { public static void waitForSomething() { if (Math.random()<0.5) { try { Thread.sleep(200);} catch(InterruptedException e){}; // used instead of Thread.yield() to ensure portability } // if } // waitForSomething } // class Simulate