An open API service indexing awesome lists of open source software.

https://github.com/chamikathereal/j2ee-timer

A simple Java EE project demonstrating EJB Timer Service for scheduling and managing automated tasks. Ideal for learning timer-based automation in enterprise applications.
https://github.com/chamikathereal/j2ee-timer

ejb jakartaee java javaee timer timer-app timer-service

Last synced: 28 days ago
JSON representation

A simple Java EE project demonstrating EJB Timer Service for scheduling and managing automated tasks. Ideal for learning timer-based automation in enterprise applications.

Awesome Lists containing this project

README

          

# πŸš€ J2EE-Timer

## πŸ“ Project Overview

**J2EE-Timer** is a simple Java EE project that demonstrates how to schedule and manage timed tasks using EJB Timer Service. This project showcases both programmatic and automatic timer creation, making it a practical reference for understanding scheduled background processing in enterprise Java applications. The implementation covers stateless session beans, timer callbacks, and integration with servlets for task managementβ€”all following best practices for reliability and scalability.

---

## πŸ“½οΈ Demo Video
[![J2EE-Timer Project Demo](https://github.com/chamikathereal/J2EE-Timer/blob/main/J2EE-Timer.png)](https://youtu.be/kAnNUfUK1kY)

---

## πŸ—‚οΈ Project Structure

```
J2EE-Timer/
β”œβ”€β”€ src/
β”‚ └── main/
β”‚ β”œβ”€β”€ java/
β”‚ β”‚ └── lk.jlat.web.eetimer/
β”‚ β”‚ β”œβ”€β”€ ejb/
β”‚ β”‚ β”‚ β”œβ”€β”€ remote/
β”‚ β”‚ β”‚ β”œβ”€β”€ AutoTimerSessionBean
β”‚ β”‚ β”‚ β”œβ”€β”€ TaskSessionBean
β”‚ β”‚ β”‚ └── TimerSessionBean
β”‚ β”‚ β”œβ”€β”€ servlet/
β”‚ β”‚ β”‚ β”œβ”€β”€ Task2
β”‚ β”‚ β”‚ └── Test
β”‚ β”‚ └── timer/
β”‚ β”‚ └── Task
β”‚ β”œβ”€β”€ resources/
β”‚ └── webapp/
β”‚ └── index.jsp
β”œβ”€β”€ pom.xml
```

## **Modules & Key Files**

#### 🟦 ejb
- **AutoTimerSessionBean**
Handles automatic scheduling using `@Schedule` annotation for recurring tasks.

- **TaskSessionBean**
Demonstrates asynchronous task execution using a managed executor service.

- **TimerSessionBean**
Manages programmatic timers, calendar-based scheduling, timer callbacks (`@Timeout`), and timer cancellation.

##

#### 🟦 servlet
- **Test**
Servlet to trigger and schedule a new timer task via `TimerSessionBean`.

- **Task2**
Servlet to cancel an existing timer by referencing the scheduled task.

##

#### 🟦 timer
- **Task**
Serializable class representing a scheduled task's identity and metadata.

---

## βš™οΈ How It Works

- βœ… **Automatic Timers:**
Use `@Schedule` in `AutoTimerSessionBean` to run methods at fixed intervals without manual intervention.

- βœ… **Programmatic Timers:**
`TimerSessionBean` creates timers dynamically using `TimerService`, schedules tasks, and handles timeout events with `@Timeout` methods.

- βœ… **Task Execution:**
`TaskSessionBean` leverages Java EE's managed executor service for asynchronous operations.

- βœ… **Servlet Integration:**
The `Test` servlet triggers new timers and stores task info in the session, while `Task2` cancels the timer based on task ID.

- βœ… **Persistence & Configuration:**
Maven-based project setup with Java 11 and Jakarta EE 10 dependencies for modern, portable deployment.

---

## ✨ Key Features

- βœ… Demonstrates both annotation-based and programmatic EJB timers
- βœ… Showcases timer callbacks and cancellation
- βœ… Integrates servlets for web-based task management
- βœ… Clean, modular code for easy learning and extension

---

## πŸ› οΈ Technologies Used

- Java 11
- Jakarta EE 10 (EJB, Servlet)
- Maven

---

## πŸ“š Learning Outcomes

- βœ… Understand EJB Timer Service for scheduled and recurring tasks
- βœ… Learn to implement both automatic and programmatic timers
- βœ… Explore asynchronous processing in Java EE
- βœ… Gain hands-on experience with modular enterprise Java applications

---

## πŸ§‘β€πŸ’» Author

Chamika Gayashan
Undergraduate Software Engineer | Sri Lanka
Linkedin: @chamikathereal
Current date: Saturday, June 21, 2025, 11:47 PM +0530