This project simulates a data processing system where multiple workers process tasks in parallel. It has been implemented in both Java and Go to compare how each language handles concurrency and error management.
The system creates several worker threads (or goroutines) that take tasks from a shared queue, process them with a short delay, and write results to an output file. It also logs when each worker starts, completes a task, or encounters an error.
-
Shared task queue for storing tasks
-
Multiple workers running in parallel
-
Thread-safe file writing
-
Logging of all activities and errors
-
Graceful shutdown after all tasks finish
-
Java: Threads, ExecutorService, BlockingQueue, try-catch
-
Go: Goroutines, Channels, WaitGroup, defer for cleanup
- Java
-
Open terminal in the project folder
-
Compile and run:
javac RideSharingSystem.java java RideSharingSystem -
Check the output file
results_java.txt
- Go
-
Open terminal in the Go folder
-
Run:
go run ridesharing.go -
Check the output file
results_go.txt
-
Console:
Worker-1 started Worker-2 processing task 3 Worker-3 completed task 5 All workers finished -
Output File:
Task 1 processed by Worker-2 (payload=ride-1) Task 2 processed by Worker-1 (payload=ride-2)
- How to use threads in Java and goroutines in Go
- How to avoid race conditions with synchronized access
- How exception and error handling differ between Java and Go