Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class SheepManager {
- private int sheepCount = 0;
- private void incrementAndReport() {
- synchronized(this) {
- System.out.print((++sheepCount)+" ");
- }
- }
- public static void main(String[] args) {
- ExecutorService service = null;
- try {
- service = Executors.newFixedThreadPool(20);
- SheepManager manager = new SheepManager();
- for(int i=0; i<10; i++)
- service.submit(() -> manager.incrementAndReport());
- } finally {
- if(service != null) service.shutdown();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement