Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class counterThreadClash
- {
- static Counter count = new Counter();
- static class t1 extends Thread
- {
- public void run()
- {
- for (int i=0;i<50000;i++) {
- count.increment();
- }
- System.out.println(count.value());
- }
- }
- static class t2 extends Thread
- {
- public void run()
- {
- for (int i=0;i<50000;i++) {
- count.increment();
- }
- System.out.println(count.value());
- }
- }
- public static void main(String [] args)
- {
- new t1().start();
- new t2().start();
- }
- }
- class Counter {
- private int c = 0;
- public void increment() {
- c++;
- }
- public void decrement() {
- c--;
- }
- public int value() {
- return c;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement