mirror of
https://github.com/davidalves04/Trabalho-Pratico-SD.git
synced 2025-12-08 20:43:32 +00:00
Update TrafficLightThread
This commit is contained in:
@@ -10,10 +10,6 @@ import sd.model.Vehicle;
|
||||
* Implements the control logic for a single TrafficLight
|
||||
* as a Runnable task that runs in its own Thread.
|
||||
*
|
||||
* This class fulfills the assignment requirements:
|
||||
* 1. Implements Runnable (to be executed by a Thread/ExecutorService).
|
||||
* 2. Implements the GREEN/RED cycle logic.
|
||||
* 3. Includes a graceful shutdown mechanism (via the 'running' flag).
|
||||
*/
|
||||
public class TrafficLightThread implements Runnable {
|
||||
|
||||
@@ -120,11 +116,11 @@ public class TrafficLightThread implements Runnable {
|
||||
vehicle.addCrossingTime(crossingTime); //
|
||||
|
||||
// 4. Update intersection statistics
|
||||
// (This requires getIntersection() to be public in IntersectionProcess)
|
||||
|
||||
process.getIntersection().incrementVehiclesSent(); //
|
||||
|
||||
// 5. Call the parent Process to send the vehicle
|
||||
// (This requires sendVehicleToNextDestination() to be public in IntersectionProcess)
|
||||
|
||||
process.sendVehicleToNextDestination(vehicle); //
|
||||
}
|
||||
}
|
||||
@@ -158,8 +154,5 @@ public class TrafficLightThread implements Runnable {
|
||||
*/
|
||||
public void shutdown() {
|
||||
this.running = false;
|
||||
// (Note: If the thread is sleeping, it will only stop
|
||||
// *after* waking up. A more immediate shutdown would require
|
||||
// calling .interrupt() on the thread running this Runnable)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user