20 likes | 158 Views
CAPITOLO 7. JAVA: MULTITHREADING E PROGRAMMAZIONE CONCORRENTE. PROGRAMMAZIONE MULTITHREAD. public class Multithread { public static void main (String args[]) { TestThrd t1, t2, t3;
E N D
CAPITOLO 7 JAVA: MULTITHREADING E PROGRAMMAZIONE CONCORRENTE
PROGRAMMAZIONE MULTITHREAD public class Multithread { public static void main (String args[]) { TestThrd t1, t2, t3; t1 = new TestThrd("Din"; (int)(Math.random())*2000); t2 = new TestThrd("Don"; (int)(Math.random())*2000); t3 = new TestThrd("Dan"; (int)(Math.random())*2000); t1.start(); t2.start(); t3.start(); } class TestThrd extends Thread { private String whoami; private int delay; public TestThrd(String s, int d) { whoami = s; delay = d; } public void run() { try { sleep(delay); } catch (InterruptedException e) {} ; System.out.println(whoami) ; } }