jhylands

javc

Feb 25th, 2016
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.63 KB | None | 0 0
  1. public class ThreadScheduling3 extends Thread {
  2.     private static class Couple {
  3.         int x = 0;
  4.         int y = 0;
  5.         public void increment() {
  6.             x++;
  7.             y++;
  8.         }
  9.     }
  10.     Couple ThreadP;
  11.     public void run() {
  12.         ThreadP.increment();
  13.     }
  14.     // Definition of main method
  15.     public static void main(String args[]) {
  16.         Couple p = new Couple();
  17.         ThreadScheduling3 t1 = new ThreadScheduling3();
  18.         ThreadScheduling3 t2 = new ThreadScheduling3();
  19.         t1.ThreadP = p;
  20.         t2.ThreadP = p;
  21.         t1.start();
  22.         t2.start();
  23.     try {
  24.         t1.join();
  25.         t2.join();
  26.     } catch(InterruptedException ie)
  27.     {};
  28.     JavaSystem.out.println("x = " +p.x + " ; y = " +p.y);
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment