GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — java-programs/Multiple_Thread/multiple_thread.java at main · IntScription/java-programs Expand file tree/ Copy pathmultiple_thread.javaMore file actions 63 lines (53 loc) · 1.52 KB / Copy pathmultiple_thread.javaFile metadata and controls63 lines (53 loc) · 1.52 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 /* * Write a java program that creates multiple threads. Main thread generates a * random integer. First child thread computes the square of next three the * numbers and there should be idle time of one second between displaying of * each computed number. Second child thread computes the cube of next three the * numbers and there should be idle time of two seconds between displaying of * each computed number. */ package Multiple_Thread; import java.util.Random; class T1 extends Thread { int val; T1(int n) { val = n; } public void run() { try { for (int i = 1; i <= 3; i++) { System.out.println((val + i) + ": " + Math.pow((val + i), 2)); Thread.sleep(1000); } } catch (InterruptedException e) { e.printStackTrace(); } } } class T2 extends Thread { int val; T2(int n) { val = n; } public void run() { try { for (int i = 1; i <= 3; i++) { System.out.println((val + i) + ": " + Math.pow((val + i), 3)); Thread.sleep(2000); } } catch (InterruptedException e) { e.printStackTrace(); } } } public class multiple_thread { public static void main(String[] args){ Random rand = new Random(); int x = rand.nextInt(11); System.out.println(x + "\n"); T1 thread1 = new T1(x); thread1.start(); T2 thread2 = new T2(x); thread2.start(); } } |
| You are visitor 01402520 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |