Skip to content

ClickerMonkey/Zource

Repository files navigation

zource

Stable

A Java library for pooling expensive resources.

Features

  • A ResourcePool can return reusable resources (Resource implementation dependent) or can generate new resources if the pool doesn't have any currently available.
  • A ResourcePool can automatically downsize it's number of resources if the number of unused resources meets a specified number for a specified amount of time.

Documentation

Example

// Create a factory that creates services for handling tasks.
ResourceFactory<TaskService> factory = new ResourceFactory<TaskService>() {
    public TaskService allocate() {
        TaskService s = new TaskService();
        s.start();
        return s;
    }
};

// Create a pool of services for handling tasks and populate it.
ResourcePool<TaskService> pool = new ResourcePool<TaskService>(factory);
pool.setMinCapacity(5);
pool.setMaxCapacity(10);
pool.setAllocateSize(5);
pool.setAllocateThreshold(50);
pool.setDeallocateSize(1);
pool.populate();

// Get a ready service to process a task
TaskService serve = pool.allocate();

// Create the task and give it to the service.
Task myTask = ...;
serve.addEvent(myTask);

// Empty pool and wait for all tasks to finish.
pool.empty();

Builds

Projects using zource:

Dependencies

About

A Java library for pooling expensive resources.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages