Thursday, 4 July 2013

Java Synchronized Thread

Java Synchronized Thread

Here is the Java Programming Program of Synchronized Threads of Miss Aisha Khan.

Note : This is Program not Presentation or PDF Kindly Understand the code and Work. Can Ask Anytime for help.


CallMe Class : 
 
package sync_t;

public class CallMe implements Runnable{
   String name;
   Thread th;
   sync_thread t;
 
   public CallMe(String n, sync_thread s)
   {
       name=n;
       t=s;
       th = new Thread(this);
       th.start();
   }
 
 
   public void run()
   {
   t.c(name);
   }
}

sync_thread Class();
 
package sync_t;

public class sync_thread {
synchronized  public void c(String m){
        System.out.println("{"+m);
        try
        {
           Thread.sleep(1000);
        }
        catch(InterruptedException ex)
        {
           
        }
        System.out.println("}");
    }
}


Main Class();




package sync_t;


public class Sync_t {

   
    public static void main(String[] args) {

        sync_thread st = new sync_thread();
       
        CallMe cl = new CallMe("Apt", st);
        CallMe cl2=new CallMe("Owais",st);
       
    }
}

0 comments:

Post a Comment

 
;