Concurrent Stack Aim
Concurrent Stack Aim
AIM:
Given a program to implement concurrent stack
ALGORITHM:
SOURCE CODE:
import java.util.concurrent.*;
public class Exercise {
static int counter = 0;
static synchronized int getAndIncrement() {
return counter++;
}
static class Improper implements Runnable {
@Override
public void run() {
for (int i = 0; i < 300; i++) {
getAndIncrement();
}
}
}
executorService.submit(new Improper());
}
executorService.shutdown();
System.out.println(counter);
}
}
OUTPUT:
RESULT:
For a given input, the program successfully executed concurrent stack