This project is a Java 25 simulation of a Car Wash and Gas Station, built to model the ProducerβConsumer Problem using custom semaphores and mutexes.
It demonstrates synchronization and safe concurrent access to shared resources in multithreaded environments.
- Cars (Producers) continuously arrive seeking service.
- Pumps (Consumers) represent service bays working in parallel.
- Synchronization ensures cars wait when the queue is full and pumps operate only when cars are available.
Car-Wash-Simulation/
β
βββ GUI/
β βββ ServiceStation.java # JavaFX 25 GUI version with animations
β
βββ GUI_TXT/
β βββ ServiceStation.java # JavaFX 25 GUI version (text-based, no animations)
β
βββ src/
β βββ ServiceStation.java # Console version (terminal-based)
β
βββ .gitignore
βββ README.md
π§ Note:
Each version includes only one file named ServiceStation.java (as required by the assignment).
All synchronization logic (Semaphores, Cars, Pumps) is contained in that file.
The project applies Operating-Systems synchronization principlesβparticularly the Bounded Buffer patternβto simulate limited waiting space and concurrent servicing.
It ensures:
- Cars cannot enter a full waiting area.
- Pumps only serve cars when available.
- Only one thread modifies the queue at a time.
- The number of serviced cars never exceeds the number of pumps.
Initializes shared resources (Queue, Mutex, Empty, Full, Pumps semaphores), reads user input, and launches producer and consumer threads.
- Represents an arriving car.
- Waits if the queue is full (
Empty.wait()). - Adds itself safely under mutex protection.
- Signals a pump that a car is available (
Full.signal()).
- Waits for available cars (
Full.wait()) and bays (Pumps.wait()). - Removes a car, services it, and releases the bay.
Custom counting semaphore with wait() (P) and signal() (V), preventing race conditions and ensuring proper synchronization.
Run from terminal:
cd src
javac ServiceStation.java
java ServiceStationExample Input
Enter waiting area capacity: 5
Enter number of service bays: 3
Example Output
C1 arrived
C2 arrived
C3 arrived
Pump 1: C1 occupied
Pump 2: C2 occupied
Pump 3: C3 occupied
C4 arrived and waiting
C5 arrived and waiting
Pump 1: C1 finishes service
Pump 1: Bay 1 is now free
Pump 1: C4 begins service
Pump 2: C5 begins service
All cars processed; simulation ends
- JavaFX 25 animated version showing cars moving between waiting areas and pumps.
- Real-time visual updates for car movement and pump usage.
Run
- Open the folder in VS Code or IntelliJ with JavaFX configured.
- Run
ServiceStation.javainside theGUIfolder.
- Simplified JavaFX 25 version with textual logs only (no animations).
- Useful for lightweight visualization.
Run
- Open in your IDE with JavaFX configured.
- Run
ServiceStation.javainside theGUI_TXTfolder.
- Open VS Code.
- Go to Extensions (Ctrl + Shift + X).
- Install:
- β Extension Pack for Java (Microsoft)
- β Optional: JavaFX Support
- Visit https://openjfx.io.
- Download JavaFX 25 SDK for your OS.
- Extract it, e.g.:
C:\javafx-sdk-25\
Add VM arguments to include JavaFX libraries.
--module-path "C:\javafx-sdk-25\lib" --add-modules javafx.controls,javafx.fxml
--module-path "/path/to/javafx-sdk-25/lib" --add-modules javafx.controls,javafx.fxml
{
"configurations": [
{
"type": "java",
"name": "Run GUI (JavaFX 25)",
"request": "launch",
"mainClass": "ServiceStation",
"vmArgs": "--module-path \"C:\\javafx-sdk-25\\lib\" --add-modules javafx.controls,javafx.fxml"
}
]
}- Open
GUI/ServiceStation.javaorGUI_TXT/ServiceStation.java. - Click Run
βΆοΈ in VS Code. - The JavaFX 25 window will launch showing the simulation.
- Java 25
- JavaFX 25
- Multithreading & Concurrency
- Custom Semaphores & Mutexes
- ProducerβConsumer (Bounded Buffer)
| Name | Student ID |
|---|---|
| Ali Radwan Farouk | 20231110 |
| Adel Hefny | 20230198 |
| Mohamed Mahmoud | 20230354 |
| Asser Ahmed | 20230655 |
Section: AI S5
Course: CS241 β Operating Systems 1
Faculty: Computers and Artificial Intelligence, Cairo University
Developed for CS241 Operating Systems (Synchronization Assignment) under TA Mena Asfour.
Demonstrates thread synchronization and bounded-buffer concurrency using Java 25 and JavaFX 25.