Skip to content

A Java concurrency utility for resource based lock management

License

Notifications You must be signed in to change notification settings

turing123/lockmanager

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LockManager

LockManager is a Java concurrency utility designed for such scenario: you have several or many "resources" to manage in your program; and for each "resource", there are several logics distributed in your program to access it, and the accesses form the "race condition".

LockManager is an elegant solution for such scenario by centrally managing the locks associated with the resources.

Note: The "resources" may be natural in your program, or may be something of some abstractions in your program.

Note: LockManager is designed for using in a single process, and if you need some kind of distributed lock management, you need some other solutions such as Apache ZooKeeper.

Examples

SimpleReadWriteLockManager<MyResource> lockmanager = new SimpleReadWriteLockManager<MyResource>();

in one thread:

lockmanager.acquireReadLock(my_resource);

// do some stuff with the resource

lockmanager.releaseReadLock(my_resource);

and in other thread:

lockmanager.acquireWriteLock(my_resource);

// do some stuff with the resource

lockmanager.releaseWriteLock(my_resource);

And please refer to the unit testing cases for more examples.

About

A Java concurrency utility for resource based lock management

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages