摘要:
为了提高性能,java提供了读写锁, 读锁: 在读的地方使用读锁,可以多个线程同时读。 写锁: 在写的地方使用写锁,只要有一个线程在写,其他线程就必须等待 例子: public static ReadWriteLock readWriteLock = new ReentrantReadWriteLo 阅读全文
摘要:
Semaphore是什么 Semaphore通常我们叫它信号量,可以用来控制同时访问特定资源的线程数量,通过协调各个线程,以保证合理的使用资源。 使用场景 通常用于哪些资源有明确访问数量限制的场景,常用于限流。 Sempahore常用方法说明 acquire() 获取一个令牌,在获取到令牌、或者被其 阅读全文
摘要:
Condition 类的 awiat 方法和 Object 类的 wait 方法等效 Condition 类的 signal 方法和 Object 类的 notify 方法等效 Condition 类的 signalAll 方法和 Object 类的 notifyAll 方法等效 Reentrant 阅读全文
摘要:
void lock(); Acquires the lock. Acquires the lock if it is not held by another thread and returns immediately, setting the lock hold count to one. If 阅读全文