This project simulates the processing of events with the highest priority using a simple event scheduling mechanism in Java. The scheduler iterates through an array of Event interfaces, prioritizing those with the highest priority. When priorities are equal, it resumes the event; otherwise, it suspends it.
- Event Creation: Create and start event threads with specified priorities.
- Priority Scheduling: The scheduler identifies and processes the event with the highest priority.
- Thread Management: Events can be suspended, resumed, or stopped based on their priority.
To run this project, ensure you have Java installed on your machine. Follow these steps:
-
Clone the Repository:
git clone https://github.com/yourusername/eventscheduler.git cd eventscheduler -
Project Structure: Make sure to move the Java files into the
eventschedulerfolder:eventscheduler/ ├── Event.java ├── EventProcessor.java ├── Main.java └── Scheduler.java -
Compile the Code: Navigate to the
eventschedulerdirectory and compile the Java files:javac *.java -
Run the Application: Execute the main class:
java Main
- Event.java: Defines the
Eventclass that implementsRunnable. It manages the event threads and their states (suspended, stopped). - EventProcessor.java: Contains the logic for processing events, simulating a task with a simple delay.
- Scheduler.java: Responsible for scheduling events based on their priority, suspending and resuming them as necessary.
- Main.java: The entry point of the application, where events are created and started.
In the Main class, you can see how to create events with different priorities:
Event[] events = {
Event.createAndStart("Backup Database", 4),
Event.createAndStart("User login", 8)
};Feel free to fork the repository and submit pull requests for any improvements or features you would like to add.
This project is licensed under the MIT License - see the LICENSE file for details.
- Inspired by the need for efficient event processing in multi-threaded applications.