This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package test.concurrency.traffic; | |
import java.util.concurrent.atomic.AtomicBoolean; | |
import java.util.concurrent.atomic.AtomicLong; | |
/** | |
* This class is thread safe (all methods synchronized) and represents a | |
* StopLight The problem assumes only one StopLight on the pavement hence the | |
* class is made singleton | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package test.concurrency.traffic; | |
import java.util.ArrayList; | |
import java.util.List; | |
import java.util.concurrent.CompletionService; | |
import java.util.concurrent.ExecutionException; | |
import java.util.concurrent.ExecutorCompletionService; | |
import java.util.concurrent.ExecutorService; | |
import java.util.concurrent.Executors; | |
import java.util.concurrent.Future; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package test.concurrency.traffic; | |
import java.util.concurrent.Callable; | |
import java.util.concurrent.atomic.AtomicInteger; | |
public class Car implements Callable<Car> { | |
private static StopLight sLight = StopLight.getInstance(); // StopLight will | |
// be injected | |
// into Car |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package test.concurrency.traffic; | |
public class Consts { | |
public static final int TOTAL_RUN_SECONDS = 100; | |
public static final int PAVEMENT_LENGTH =100; | |
public static final int CAR_1_START_POS = 24; | |
public static final int CAR_2_START_POS = 12; | |
public static final int CAR_3_START_POS = 0; | |
public static final int ONE_SEC =1000; | |
public static final int SWITCH_INTERVAL = 10; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package test.concurrency.traffic; | |
public enum LightState { | |
RED, GREEN; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.abhi.ds.heap; | |
public class HeapTestHarness { | |
public static void main(String a[]) { | |
Heap<Integer> hp = new Heap<Integer>(); | |
hp.addItem(5); | |
hp.addItem(3); | |
hp.addItem(2); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.abhi.ds.heap; | |
import java.util.ArrayList; | |
import java.util.List; | |
import java.util.NoSuchElementException; | |
public class Heap<T extends Comparable<T>> { | |
private List<T> items; |