公众号:架构师与哈苏
关注公众号进入it交流群! 公众号:架构师与哈苏 不定时都会推送一些实用的干货。。。
摘要: 为了提高性能,java提供了读写锁, 读锁: 在读的地方使用读锁,可以多个线程同时读。 写锁: 在写的地方使用写锁,只要有一个线程在写,其他线程就必须等待 例子: public static ReadWriteLock readWriteLock = new ReentrantReadWriteLo 阅读全文
posted @ 2021-08-09 17:05 公众号/架构师与哈苏 阅读(46) 评论(0) 推荐(0) 编辑
摘要: Semaphore是什么 Semaphore通常我们叫它信号量,可以用来控制同时访问特定资源的线程数量,通过协调各个线程,以保证合理的使用资源。 使用场景 通常用于哪些资源有明确访问数量限制的场景,常用于限流。 Sempahore常用方法说明 acquire() 获取一个令牌,在获取到令牌、或者被其 阅读全文
posted @ 2021-08-09 16:14 公众号/架构师与哈苏 阅读(174) 评论(0) 推荐(0) 编辑
摘要: Condition 类的 awiat 方法和 Object 类的 wait 方法等效 Condition 类的 signal 方法和 Object 类的 notify 方法等效 Condition 类的 signalAll 方法和 Object 类的 notifyAll 方法等效 Reentrant 阅读全文
posted @ 2021-08-09 15:21 公众号/架构师与哈苏 阅读(209) 评论(0) 推荐(0) 编辑
摘要: 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 阅读全文
posted @ 2021-08-09 14:42 公众号/架构师与哈苏 阅读(122) 评论(0) 推荐(0) 编辑