All Projects → pqpo → Plock

pqpo / Plock

Licence: apache-2.0
🔐PLock is a simple and efficient cross-process lock, also support read-write lock. (简单高效的跨进程锁,支持读写锁分离)

Programming Languages

java
68154 projects - #9 most used programming language

Labels

Projects that are alternatives of or similar to Plock

Redislock
Simplified distributed locking implementation using Redis
Stars: ✭ 370 (+285.42%)
Mutual labels:  lock
Lock
Auth0's signin solution
Stars: ✭ 997 (+938.54%)
Mutual labels:  lock
Yubikeylockd
Simple daemon for locking and unlocking macOS with Yubikey
Stars: ✭ 78 (-18.75%)
Mutual labels:  lock
Passcodeview
Material Design PasscodeView for Android.
Stars: ✭ 513 (+434.38%)
Mutual labels:  lock
Mt
tlock, RWMUTEX, Collab, USM, RSem and other C++ templates for Windows to provide read/write mutex locks, various multithreading tools, collaboration, differential updates and more
Stars: ✭ 18 (-81.25%)
Mutual labels:  lock
Alfred Lock
Alfred 3 workflow to lock your Mac
Stars: ✭ 54 (-43.75%)
Mutual labels:  lock
Lock
Creates and manages locks, a mechanism to provide exclusive access to a shared resource.
Stars: ✭ 299 (+211.46%)
Mutual labels:  lock
Protectjs
Private methods & properties in JavaScript
Stars: ✭ 94 (-2.08%)
Mutual labels:  lock
Dyfauthidandgesturelock
手势密码解锁和 TouchID (指纹) / FaceID(面容) 解锁,代码简洁高效。(Gesture passcode unlocking and TouchID (fingerprint) / FaceID (facial features) unlocking, its code is concise and efficient.) https://github.com/dgynfi/DYFAuthIDAndGestureLock
Stars: ✭ 20 (-79.17%)
Mutual labels:  lock
Lock System
Lock your system
Stars: ✭ 69 (-28.12%)
Mutual labels:  lock
Spring Boot Klock Starter
基于redis的分布式锁组件,简单方便快捷接入项目,使项目拥有分布式锁能力
Stars: ✭ 546 (+468.75%)
Mutual labels:  lock
Lock
Lock library to provide serialized execution of PHP code.
Stars: ✭ 775 (+707.29%)
Mutual labels:  lock
Repo Lockdown
GitHub Action that immediately closes and locks issues and pull requests
Stars: ✭ 56 (-41.67%)
Mutual labels:  lock
Redlock Rb
Redlock is a redis-based distributed lock implementation in Ruby
Stars: ✭ 385 (+301.04%)
Mutual labels:  lock
Pause On Lock
Pause/Resume your music player when locking/unlocking your Linux desktop.
Stars: ✭ 79 (-17.71%)
Mutual labels:  lock
Diplomat
A HTTP Ruby API for Consul
Stars: ✭ 358 (+272.92%)
Mutual labels:  lock
Kioskmode Android
Screen Pinning Android Lollipop with enable Device Administrator without Root needed
Stars: ✭ 40 (-58.33%)
Mutual labels:  lock
Pinlockview
A clean, minimal, highly customizable pin lock view for Android
Stars: ✭ 1,340 (+1295.83%)
Mutual labels:  lock
Limiter
一个注解使你的SpringBoot项目获得分布式锁和限流器能力
Stars: ✭ 93 (-3.12%)
Mutual labels:  lock
Sidekiq Lock
Simple redis-based lock mechanism for your sidekiq workers
Stars: ✭ 60 (-37.5%)
Mutual labels:  lock

PLock

PLock is a simple and efficient cross-process lock, also supports read-write lock.

License

If you like this, welcome to star/fork it or follow me.

PLock is an Android library, it makes Android to support cross-process lock, not only that, it can also be transfer to support Java project.
It is easy to use and runs efficiently.
PLock can acquire locks in either blocking(lock) or non-blocking(tryLock) mode. In blocking mode, it will block the current thread in the process if the lock you acquire is already hold by another process, that only returns false in non-blocking mode.
PLock also supports read-write lock cross process,If one process holds a read lock, the other process can also acquire a read lock successfully,and cannot acquire a write lock. If one process holds a write lock, the other process cannot acquire any read or write lock.
You can also use PLock as a file lock, In fact, it is based on file locks that using fcntl

acquire read lock acquire write lock
no lock allow allow
one or more read locks allow disallow
one write lock disallow disallow

Getting started

In your build.gradle:

allprojects {
    repositories {
        maven { url 'https://jitpack.io' }
    }
}

dependencies {
    implementation 'com.github.pqpo:PLock:{last-version}'
}

Usage

  • Step 1. get a default PLock object, and you can also create one by yourself.
  • Step 2. acquire locks.
  • Step 3. unlock.
  • Step 4. release if necessary.

For example:

PLock pLock = PLock.getDefault();
// OR you can also use it as a file lock:
// PLock pLock = new PLock(file);

pLock.lock(); 
try {
    // to do something...
} catch (Exception e) {
    // errors
} finally {
    pLock.unlock(); 
}

// in non-blocking mode
if(pLock.tryLock()) {
   try {
       // to do something...
   } catch (Exception e) {
       // errors
   } finally {
       pLock.unlock(); 
   }
} 

// non-block read lock
if(pLock.tryReadLock()) {
    // to do something...
} 
// non-block write lock
if(pLock.tryWriteLock()) {
    // to do something...
} 

// etc.


// pLock.release(); 

Play with samples, have fun!

You can clone this repository, then run 'debug' build variant and 'second' build variant, after that you can see two applications running on your phone which named PLock-FirstProcess and PLock-SecondProcess.

Or download PLock-FirstProcess and PLock-SecondProcess.

PLock-first-process PLock-second-process

About Me:

License

Copyright 2018 pqpo

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].