Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class ThreadScheduling3 extends Thread {
- private static class Couple {
- int x = 0;
- int y = 0;
- public void increment() {
- x++;
- y++;
- }
- }
- Couple ThreadP;
- public void run() {
- ThreadP.increment();
- }
- // Definition of main method
- public static void main(String args[]) {
- Couple p = new Couple();
- ThreadScheduling3 t1 = new ThreadScheduling3();
- ThreadScheduling3 t2 = new ThreadScheduling3();
- t1.ThreadP = p;
- t2.ThreadP = p;
- t1.start();
- t2.start();
- try {
- t1.join();
- t2.join();
- } catch(InterruptedException ie)
- {};
- JavaSystem.out.println("x = " +p.x + " ; y = " +p.y);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment