GithubHelp home page GithubHelp logo

jpool's Introduction

Based on the current implementation of JPool, here is the updated README:

# JPool

JPool is a simple, lightweight, and easy-to-use worker pool implementation in Java.

## Features

- **Task Queue**: JPool uses a `BlockingQueue` to store tasks to be processed. This queue is thread-safe, allowing multiple workers to fetch tasks concurrently.

- **Worker Pool**: JPool maintains a pool of worker threads. Each worker can fetch tasks from the task queue and execute them. The size of the worker pool is configurable at the time of JPool creation.

- **Task Submission**: Tasks can be submitted to JPool using the `submit` method. If JPool has been shut down, an `IllegalStateException` will be thrown.

- **Graceful Shutdown**: JPool provides a `shutdown` method for gracefully shutting down the worker pool. This method will wait for all workers to finish their current tasks before returning.

- **Task Monitoring**: JPool provides several methods for monitoring the status of tasks:
  - `getCompletedTasks`: Returns the total number of tasks completed by all workers.
  - `getWaitingTasks`: Returns the number of tasks waiting in the queue.
  - `getRunningTasks`: Returns the number of tasks currently being run by workers.

## Usage

To use JPool, first create a new `JPool` instance with the desired number of workers. Then, submit tasks to the pool using the `submit` method. When all tasks are finished, call the `shutdown` method to gracefully shut down the worker pool.

Here is a simple example:

```java
// Create a new JPool with 4 workers
JPool pool = new JPool(4);

// Submit tasks to the pool
for (int i = 0; i < 10; i++) {
    pool.submit(() -> {
        // This is the task to be executed
        System.out.println("Task executed by " + Thread.currentThread().getName());
    });
}

// Gracefully shut down the pool
pool.shutdown();

In this example, we create a new JPool with 4 workers. We then submit 10 tasks to the pool. Each task simply prints a message to the console. Finally, we call the shutdown method to wait for all tasks to finish and shut down the pool.

Performance

JPool is designed to be lightweight and efficient. However, the performance may vary depending on the nature of the tasks and the hardware resources available. It is recommended to adjust the size of the worker pool and the type of the task queue based on the specific use case.

License

JPool is open-sourced software licensed under the MIT license.


This README provides a clear and concise description of JPool's features and usage. It also includes a note on performance and a link to the license.

jpool's People

Contributors

kpshao avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.