unlock

读写锁(ReentrantReadWriteLock)

ε祈祈猫儿з 提交于 2019-11-27 14:10:46
重点:   1、读锁共享   2、写锁互斥   3、读写锁互斥 锁降级 :将写锁降级为读锁。(先获取写锁,再获取读锁,再释放写锁,最后释放读锁) 造成锁降级的原因:出于性能考虑,一般情况下,都将锁定的动作,精确到具体的语句块,在两个锁的语句块之间,有可能线程的交替执行,造成线程安全问题。 解决的方法:   1、将锁的范围扩大。   2、使用锁降级。 为什么需要锁降级:  伪代码: w.lock();//写锁 writeSomeDate();//修改某些数据 w.unlock();//释放写锁 r.lock();//读锁 readSomeDate();//获取某个数据 r.unlock();//释放读锁 此时,获取数据的时候,就有线程安全问题。 修改后的代码为: w.lock();//写锁 writeSomeDate();//修改某些数据 r.lock();//读锁 w.unlock();//释放写锁 readSomeDate();//获取某个数据 r.unlock();//释放读锁 将读锁的锁定动作,放入到写锁的释放之前,就可以将锁降级为读锁。    来源: https://www.cnblogs.com/chen--biao/p/11366952.html

Android — What happens when device is unlocked?

安稳与你 提交于 2019-11-27 12:16:32
问题 I am trying to understand the intents that get launched when the device is unlocked. For eg: Say my activity is running, and I press the power button (screen off, to lock the phone). INTENT.ACTION_SCREEN_OFF is launched. The activity is paused and the screen goes blank. Now, when I press the power button again (INTENT.SCREEN_ON gets launched), the activity's onResume method is called. But the device is not yet unlocked. What happens when the device is unlocked? To put it simply, what is the

Android9.0抓取qxdm log

孤者浪人 提交于 2019-11-27 07:22:26
9.0平台不能直接使用暗码抓取qxdm log,使其root就可以了 1.进入fastboot模式 adb reboot bootloader 2.使能unlock(这步会使手机恢复出厂设置) fastboot oem unlock-flash(使能unlock) 按音量下键使其unlock 再按power键确认 3.再次进入fastboot模式, 使能root fastboot oem enable-rooting 4.重启手机 adb root adb shell setenforce 0 来源: https://blog.csdn.net/qq_44963514/article/details/99546980

Android Activity lifecycle and locking/unlocking device

自作多情 提交于 2019-11-27 00:36:14
问题 I just found that when the device has lock screen enabled, the followings happen. For this activity, android:screenOrientation="landscape" is set in the manifest. Then I perform the followings with my phone in a portrait mode. The user opens an activity. onCreated() is called onStart() is called onResume() is called The user LOCKS the device 4.5 onPause is called() onDestroy() is called onCreate() is called onStart() is called onResume() is called 8.5 onPause is called() The user UNLOCKS the

锁机制

这一生的挚爱 提交于 2019-11-26 19:07:31
悲观锁: 悲观锁悲观的认为每一次操作都会造成更新丢失问题,在每次查询时加上排他锁 每次去拿数据的时候都认为别人会修改,所以每次在拿数据的时候都会上锁,这样别人想拿这个数据就会block直到它拿到锁。传统的关系型数据库里边就用到了很多这种锁机制,比如行锁,表锁等,读锁,写锁等,都是在做操作之前先上锁。 Select * from xxx for update ; 缺点:因为只能保证一个连接进行操作,所以效率低 乐观锁: 乐观锁会乐观的认为每次查询都不会造成更新丢失,利用版本字段控制 重入锁: 重入锁也叫做递归锁,指的是同一线程 外层函数获得锁之后 ,内层递归函数仍然有获取该锁的代码,但外层函数不受内层函数影响,例如当内部释放锁(unlock)后,外部不会释放。在JAVA环境下 ReentrantLock 和synchronized 都是可重入锁。 synchronized : public class Test implements Runnable { //外层 public synchronized void get() { System.out.println("name:" + Thread.currentThread().getName() + " get();"); set(); } //内层 public synchronized void set() { System

2、Java5多线程---Lock

ε祈祈猫儿з 提交于 2019-11-26 17:11:41
Java5多线程---Lock 在Java5中的并发包 java.util.concurrent.locks 下有个接口Lock ,这个接口是实现同步访问的另外一种形式,Lock为锁和等待条件提供一个框架的接口,它不同于内置同步和监视器。以前我们都是在用synchronized 关键字,用于修饰方法(同步方法)或者同步代码块来实现同步访问,在java5中我们可以用Lock来实现同步的访问。我们都知道用关键字synchronized修饰的方法或者synchronized代码块,当一个线程获取对应的监控器(对象锁)时候,并执行synchronized里面的代码的时候,其它线程会一直处于等待此线程释放监视器才有机会进行执行,此线程释放监视器有两种,一是此线程执行完毕,二是出现异常java虚拟机会让其自动释放监视器。 试想下在当前获取监视器的线程进行耗时的操作(如:进行IO操作或者直接说进行休眠),那么其它线程将无限的进行等待下去。synchronized方法或者 synchronized代码块执行完毕之后会自动释放监视器,而Lock需要用户自己手动释放,但lock 是更细粒度控制同步问题。 一、Lock 1、Lock是 java.util.concurrent.locks包下的一个接口,它实现提供了比使用synchronized方法和语句可获得的更广泛的锁定操作。锁变成了更加的灵活性

How can I detect screen lock/unlock events on the iPhone?

有些话、适合烂在心里 提交于 2019-11-26 16:21:03
How can I detect screen lock/unlock events on the iPhone? When the user unlocks it, I want to show a notification alert from my iPhone app. (For Just like Broadcast Receiver for screen unlock in Android.) Oliver Actually I want the if I exit the application and lock the iPhone , and after some time I have unlock the iPhone , then exit Applications show the notifications or Alert the Start-up the Applications. You can't do that on the iPhone. Rohit Kashyap Check this out, I wanted to detect the lock/unlock events, I solved it by Darwin notifications. You can detect the event when the device is

java多线程总结-同步之ReentrantLock

杀马特。学长 韩版系。学妹 提交于 2019-11-26 15:59:33
文章目录 1 ReentrantLock与synchronized对比 2.示例用法 2.1 基本用法 2.2 尝试锁 2.3 可打断 2.4 公平锁 1 ReentrantLock与synchronized对比 ReentrantLock与synchronized都是为了同步加锁,但ReentrantLock相对效率比synchronized高,量级较轻。 synchronized在JDK1.5版本开始,尝试优化。到JDK1.7版本后,优化效率已经非常好了。在绝对效率上,不比reentrantLock差多少。使用ReentrantLock, 必须手工释放锁标记 。一般都是在finally代码块中定义释放锁标记的unlock方法。 2.示例用法 2.1 基本用法 lock()与unlock()就像synchronized同步代码块的开始与结束,使用ReentrantLocky一定要记得unlock()解锁 package com.bernardlowe.concurrent.t03; import java.util.concurrent.TimeUnit; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; public class Test_01 {

How can I detect screen lock/unlock events on the iPhone?

丶灬走出姿态 提交于 2019-11-26 04:46:38
问题 How can I detect screen lock/unlock events on the iPhone? When the user unlocks it, I want to show a notification alert from my iPhone app. (For Just like Broadcast Receiver for screen unlock in Android.) 回答1: Actually I want the if I exit the application and lock the iPhone , and after some time I have unlock the iPhone , then exit Applications show the notifications or Alert the Start-up the Applications. You can't do that on the iPhone. 回答2: Check this out, I wanted to detect the lock