wajd
JCHJava Community | Help. Code. Learn.
•Created by wajd on 11/5/2024 in #java-help
synchronization or semaphores to be specific
hi there, i'm trying to understand the concept of threads and synchronization by this put together code but it's weirdly printing chefs preparing meals before customers even ordering? can i have help on the code or be given resources how to fix it atleast? this is the output for reference
[Arrival] Customer 4 arrives.
[Arrival] Customer 2 arrives.
[Seating] Customer 4 is seated.
[Arrival] Customer 1 arrives.
[Seating] Customer 1 is seated.
[Seating] Customer 2 is seated.
[Arrival] Customer 3 arrives.
[Seating] Customer 3 is seated.
[Preparation] Chef starts preparing meal for Customer 1
[Preparation] Chef starts preparing meal for Customer 4
[Order] Customer 4 placed an order: Salad
[Order] Customer 1 placed an order: Burger
[Order] Customer 3 placed an order: Pasta
[Order] Customer 2 placed an order: Pizza
[Departure] Customer 4 finishes eating and leaves.
[Departure] Customer 3 finishes eating and leaves.
[Table Availability] Table is now available for other customers.
[Departure] Customer 2 finishes eating and leaves.
[Table Availability] Table is now available for other customers.
[Departure] Customer 1 finishes eating and leaves.
[Table Availability] Table is now available for other customers.
[Table Availability] Table is now available for other customers.
[Serving] Meal for Customer 4 is served.
[Meal Ready] Meal for Customer 4 is ready for serving.
[Preparation] Chef starts preparing meal for Customer 3
[Meal Ready] Meal for Customer 1 is ready for serving.
[Serving] Meal for Customer 1 is served.
[Preparation] Chef starts preparing meal for Customer 2
[Meal Ready] Meal for Customer 3 is ready for serving.
[Serving] Meal for Customer 3 is served.
[Meal Ready] Meal for Customer 2 is ready for serving.
[Serving] Meal for Customer 2 is served.
[Arrival] Customer 4 arrives.
[Arrival] Customer 2 arrives.
[Seating] Customer 4 is seated.
[Arrival] Customer 1 arrives.
[Seating] Customer 1 is seated.
[Seating] Customer 2 is seated.
[Arrival] Customer 3 arrives.
[Seating] Customer 3 is seated.
[Preparation] Chef starts preparing meal for Customer 1
[Preparation] Chef starts preparing meal for Customer 4
[Order] Customer 4 placed an order: Salad
[Order] Customer 1 placed an order: Burger
[Order] Customer 3 placed an order: Pasta
[Order] Customer 2 placed an order: Pizza
[Departure] Customer 4 finishes eating and leaves.
[Departure] Customer 3 finishes eating and leaves.
[Table Availability] Table is now available for other customers.
[Departure] Customer 2 finishes eating and leaves.
[Table Availability] Table is now available for other customers.
[Departure] Customer 1 finishes eating and leaves.
[Table Availability] Table is now available for other customers.
[Table Availability] Table is now available for other customers.
[Serving] Meal for Customer 4 is served.
[Meal Ready] Meal for Customer 4 is ready for serving.
[Preparation] Chef starts preparing meal for Customer 3
[Meal Ready] Meal for Customer 1 is ready for serving.
[Serving] Meal for Customer 1 is served.
[Preparation] Chef starts preparing meal for Customer 2
[Meal Ready] Meal for Customer 3 is ready for serving.
[Serving] Meal for Customer 3 is served.
[Meal Ready] Meal for Customer 2 is ready for serving.
[Serving] Meal for Customer 2 is served.
8 replies