Saturday, 11 January 2014

Advanced Java_ Multi-threading Part 2 -- Basic Thread Synchronization - 3


===
package Demo4;

import java.util.Scanner;

/**
 * Title:- Advanced Java_ Multi-threading Part 2 -- Basic Thread Synchronization - 3
 * Note:-- Basic Thread synchronization
 * @author Dharmaraj.Net
 * There are two kind of problem encounter when thread sharing same data
 * First one is data being cashed abd secibd thread leaving
 * Propose of volatile key word in java and basic thread synchronization
 * 
 */

class Processor extends Thread{
 private boolean running = true;
 public void run(){
  while(true){
   System.out.println("Hello");
   try {
    Thread.sleep(100);
   } catch (InterruptedException e) {
    e.printStackTrace();
   }
  }
 }
 
 public void shotDown()
 {
  running = false;
 }
}

public class App {

 public static void main(String[] args) {
  Processor proc1 = new Processor();
  proc1.start();
  
  System.out.println("Press return to Stop....");
  Scanner scanner = new Scanner(System.in);
  scanner.nextLine();
  
  
 }
}
=== 

No comments:

Post a Comment