Multi Threading

  • Uploaded by: Omar Farooq
  • 0
  • 0
  • November 2019
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Multi Threading as PDF for free.

More details

  • Words: 138
  • Pages: 3
MULTITHREADING PROGRAM: import java.io.*; class evenThread extends Thread { evenThread() { super("demothread"); start(); } public void run() { try { for(int i=1;i<=20;i=i+2) { System.out.println("even no"+i); Thread.sleep(200); } } catch(InterruptedException ie) { System.out.println(ie); } System.out.println("even thread terminates"); } } class oddThread extends Thread { oddThread() { super("demothread"); start(); } public void run() { try

{ for(int i=1;i<=20;i=i+1) { System.out.println("odd no"+i); Thread.sleep(200); } } catch(InterruptedException ie) { System.out.println("even thread terminates"); } } } class multiple5Thread extends Thread { multiple5Thread() { super("demothread"); start(); } public void run() { try { for(int i=1;i<=50;i=i+5) { System.out.println("even no"+i); Thread.sleep(500); } } catch(InterruptedException ie) { System.out.println("multilpe5 thread terminates"); } } } class sample { public static void main(Stirng str[]) {

evenThread t=new evenThread(); oddThread t1=new oddThread(); multiple5Thread t2=new multilpe5Thread(); try { Thread.join(); Thread1.join(); Thread2.join(); } catch(InterruptedException ie) { System.out.println(ie); } System.out.println("Main thread terminates"); } }

Related Documents

Multi Threading
November 2019 31
Multi Threading
November 2019 31
Multi Threading
November 2019 22
Multi Threading 3
October 2019 32
Multi Threading Overview
November 2019 20

More Documents from "Shraddha Sheth "