Monday, 16 February 2015

MultiThreading Example:-Using single application for more


package com.bsl.model;
class TestMultiNaming1 extends Thread{
    static int a, b, c;
 public void run(){
   
     if(Thread.currentThread().getName().equalsIgnoreCase("addition"))
     {
        a= m1();
     System.out.println("addition done"+a+"reading of file done here");
       
         }
     if(Thread.currentThread().getName().equalsIgnoreCase("multiply"))
     {
        b= m2();
             System.out.println("multiply done"+b+"file has been pasted to someother location");
         }
     if(Thread.currentThread().getName().equalsIgnoreCase("equal"))
     {
             c=a+b;  System.out.println("total done"+c);      
         }
 }
 int m1(){
     System.out.println("addition");
    return 9;}
    int m2(){
        System.out.println("multiply");
       return 4;}
    int tt(){
        System.out.println("total");
       return 9;}
public static void main(String args[]){
 TestMultiNaming1 t1=new TestMultiNaming1();
 TestMultiNaming1 t2=new TestMultiNaming1();
 TestMultiNaming1 t3=new TestMultiNaming1();
 t1.setName("addition");
 t2.setName("Multiply");
 t3.setName("equal");
 t1.start();

 try{
  t1.join();
     t2.start();
     t2.join();
   
 }catch(Exception e){System.out.println(e);}
 t3.start();
 }
}  

No comments:

Post a Comment