Skip to content

arianam21/Queue-Simulation-System-Java

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Queue Simulation System (Java Swing)

A desktop application developed in Java that simulates the distribution of clients (Tasks) to multiple queues (Servers) using various scheduling strategies.


Key Features

Simulation Setup and Generation

  • Time-Based Simulation: The application runs a discrete, step-by-step simulation cycle, defined by a user-set maximum time limit.
  • Client/Task Generation: A specified number of clients (Tasks) are generated randomly, with arrival and service time intervals defined by the user in the GUI.
  • Task Ordering: Generated tasks are sorted based on their arrival time (arrivalTime) before the simulation begins.

Scheduling Strategies (Selection Policy)

The application allows selection from two task distribution policies, managed by the Scheduler:

  • SHORTEST_QUEUE: Tasks are dispatched to the Server (queue) with the smallest current number of waiting tasks.
  • SHORTEST_TIME: Tasks are dispatched to the Server with the minimum total current waiting period (waitingPeriod).

Interface and Logging

  • Graphical User Interface (GUI): A Swing interface allows configuration of all simulation parameters (Client Count, Queue Count, Time Limit, Strategy, Arrival/Service Time Ranges).
  • Real-Time Visualization: The interface visually updates the state of the queues (Servers) and the waiting tasks at every time step.
  • Event Logging: All simulation events (state of queues and waiting tasks at each second) are logged to an output file named LogOfEvents.txt.

Technology and Architecture

  • Language: Java
  • Graphical Interface: Swing (AWT/Swing)
  • Multi-threading: Each queue (Server) runs on its own separate thread (Thread).
  • Concurrency: Uses concurrent structures like BlockingQueue for tasks and AtomicInteger for managing the waiting period within the Server class.
  • Design Pattern: Implements the Strategy pattern (Strategy, ShortestQueueStrategy, TimeStrategy) for flexible task allocation.

Project Structure

  • Model:
    • Task.java: Represents a client, implementing Comparable for sorting by arrival time.
    • Server.java: Represents a queue, handling tasks as a Runnable thread.
  • BusinessLogic:
    • SimulationManager: Main control class for the simulation lifecycle and task generation.
    • Scheduler: Dispatches tasks using the selected Strategy.
    • Strategy Interface and Implementations: Defines the task allocation logic.
  • GUI:
    • SimulationFrame.java: The Swing interface for configuration and real-time visualization.

How to Run the Project

  1. Ensure you have a JDK (Java Development Kit) installed.
  2. The main execution class is BusinessLogic.SimulationManager (which launches the SimulationFrame).
  3. The application will automatically create the LogOfEvents.txt file in the root directory upon simulation completion.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages