Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package intropackage;
- public class Driver {
- public static void main(String[] args) throws InterruptedException {
- A a = new A();
- A a2 = new A();
- Display display = new Display(a,"FARHAN");
- Display display2 = new Display(a2 , "TANVIR");
- display.start();
- display2.start();
- }
- }
- public class A{
- public void wish(String name)
- {
- for(int i=0;i<5;i++)
- {
- System.out.println("HABIZABI START BY "+Thread.currentThread());
- }
- synchronized (A.class) {
- for(int i=0;i<10;i++)
- {
- System.out.print("GOOD MORNING: ");
- try {
- Thread.sleep(1000);
- } catch (InterruptedException e) {
- System.out.println("INTERRUPTED");
- }
- System.out.println(name);
- }
- }
- for(int i=0;i<5;i++)
- {
- System.out.println("HABIZABI END BY "+Thread.currentThread());
- }
- }
- public class Display extends Thread {
- A object;
- String name;
- public Display(A object , String name) {
- this.name=name;
- this.object=object;
- }
- public void run()
- {
- object.wish(name);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement