Thursday, 26 April 2018

//join method in multithreading.........................

if a thread wants to wait until completing some other thread  then we should go for join().......


package multithreading;

public class MarriageDateFixed extends Thread{

public void run()
{
for(int i=0;i<10;i++)
{
System.out.println("MarriageDateFixed");
}
}

}

================================================================================
package multithreading;

public class MarriageCardPrinting extends Thread
{

public void run()
{
for(int i=0;i<10;i++)
{
System.out.println("MarriageCardPrinting");
}
}

}


=================================================================================

package multithreading;

public class MarriageCardDistribution  extends Thread
{
public void run()
{
for(int i=0;i<10;i++)
{
System.out.println("MarriageCardDistribution");
}
}
}
==============================================================================

package multithreading;

public class MarriageMain {
public static void main(String[] args) throws InterruptedException {
MarriageDateFixed mdf=new MarriageDateFixed();
MarriageCardPrinting mcp=new MarriageCardPrinting();
MarriageCardDistribution mcd=new MarriageCardDistribution();
mdf.start();
mdf.join();//
mcp.start();
mcp.join();
mcd.start();
}

}
================================================================================

Run without Join:----------------------------
MarriageCardPrinting
MarriageCardPrinting
MarriageCardPrinting
MarriageCardPrinting
MarriageCardPrinting
MarriageCardPrinting
MarriageCardPrinting
MarriageCardPrinting
MarriageCardPrinting
MarriageCardPrinting
MarriageDateFixed
MarriageDateFixed
MarriageDateFixed
MarriageDateFixed
MarriageDateFixed
MarriageDateFixed
MarriageDateFixed
MarriageDateFixed
MarriageDateFixed
MarriageDateFixed
MarriageCardDistribution
MarriageCardDistribution
MarriageCardDistribution
MarriageCardDistribution
MarriageCardDistribution
MarriageCardDistribution
MarriageCardDistribution
MarriageCardDistribution
MarriageCardDistribution
MarriageCardDistribution




Run With Join---------------------------------------

MarriageDateFixed
MarriageDateFixed
MarriageDateFixed
MarriageDateFixed
MarriageDateFixed
MarriageDateFixed
MarriageDateFixed
MarriageDateFixed
MarriageDateFixed
MarriageDateFixed
MarriageCardPrinting
MarriageCardPrinting
MarriageCardPrinting
MarriageCardPrinting
MarriageCardPrinting
MarriageCardPrinting
MarriageCardPrinting
MarriageCardPrinting
MarriageCardPrinting
MarriageCardPrinting
MarriageCardDistribution
MarriageCardDistribution
MarriageCardDistribution
MarriageCardDistribution
MarriageCardDistribution
MarriageCardDistribution
MarriageCardDistribution
MarriageCardDistribution
MarriageCardDistribution
MarriageCardDistribution

No comments:

Post a Comment