unlock

Java 8新特性探究(十)StampedLock将是解决同步问题的新宠

Deadly 提交于 2019-11-28 22:56:44
Java8就像一个宝藏,一个小的API改进,也足与写一篇文章,比如同步,一直是多线程并发编程的一个老话题,相信没有人喜欢同步的代码,这会降低应用的吞吐量等性能指标,最坏的时候会挂起死机,但是即使这样你也没得选择,因为要保证信息的正确性。所以本文决定将从synchronized、Lock到Java8新增的StampedLock进行对比分析,相信StampedLock不会让大家失望。 synchronized 在java5之前,实现同步主要是使用synchronized。它是 Java语言的关键字,当它用来修饰一个方法或者一个代码块的时候,能够保证在同一时刻最多只有一个线程执行该段代码。 有四种不同的同步块: 实例方法 静态方法 实例方法中的同步块 静态方法中的同步块 大家对此应该不陌生,所以不多讲了,以下是代码示例 synchronized(this) // do operation } 小结: 在多线程并发编程中Synchronized一直是元老级角色,很多人都会称呼它为重量级锁,但是随着Java SE1.6对Synchronized进行了各种优化之后,性能上也有所提升。 Lock 它是Java 5在java.util.concurrent.locks新增的一个API。 Lock是一个接口,核心方法是lock(),unlock(),tryLock()

How to force delete a file? [closed]

自古美人都是妖i 提交于 2019-11-28 22:40:12
This question exists because it has historical significance, but it is not considered a good, on-topic question for this site, so please do not use it as evidence that you can ask similar questions here. How can i force Windows XP to delete file that is currently being used by some application? Konstantin Tarkus You have to close that application first. There is no way to delete it, if it's used by some application. UnLock IT is a neat utility that helps you to take control of any file or folder when it is locked by some application or system. For every locked resource, you get a list of

JMM内存模型详解(一)

十年热恋 提交于 2019-11-28 05:00:33
本文开始死磕JMM(Java内存模型)由于知识点较多,分来写 该文为JMM第一篇 技术往往是枯燥的,本文文字较多 1. JMM是什么? 其实JMM很好理解,我简单的解释一下,在Java多线程中我们经常会涉及到两个概念就是线程之间是如何通信和线程之间的同步,那什么是线程之间的通信呢,其实就是两个线程之间互相交换信息线程之间通信的方式共有两种: 一种就是共享内存,和消息传递 。在共享内存中的并发模型中线程是通过读取主内存的共享信息来进行隐性通信的。在消息传递通信中线程之间没有公共的状态,只能通过发送消息来进行显性通信。然而这只是线程通信,那么同步呢,同步就是在多线程的情况下有顺序的去执行。在共享内存中同步时显式进行的,在代码中我们必须要去指定方法需要同步执行比如说加同步锁等。在消息传递的并发模型中发送消息必须是在消接收之前,所以同步时隐式的。 2.为什么要涉及到线程并发通信 java内存模型其实可以说是Java并发内存模型,在Java中是采用的共享内存模型的方式,所以Java线程之间的通信是隐式进行的,对我们是完全透明的,如果你不了解通信机制的话会产生各种线程可见性的问题。其实在Java中所有的静态域,域和数组元素都存在堆内存中,堆内存在线程中是共享的一般我们都称之为共享变量,局部变量,方法定义参数和异常处理参数不会在线程中共享,所以不会存在线程可见性的问题

Android Activity lifecycle and locking/unlocking device

孤人 提交于 2019-11-28 04:42:31
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 device onResume() is called onDestroy() is called onCreate() is called onStart() is called onResume()

JAVA并发编程-并发编程基础

夙愿已清 提交于 2019-11-28 01:47:42
并发编程基础 1.CPU的多级缓存 数据的读取和存储都经过高速缓存,缓存和主存都链接在总线上。 使用多级缓存是为了缓解CPU和内存之间的速度不匹配问题 缓存的局部性原理: 时间局部性:如果某个数据被访问,那么不久的将来可能再次被访问 空间局部性:如果某个数据被访问,那么他相邻的数据可能再次被访问 缓存一致性MESI保证多个CPU cache之前缓存共享数据的一致性 2.CPU多级缓存的乱序执行优化 处理器为了提高速度做出违背代码原有顺序的优化。 int a = 100; int b = 20; int result = a*b; cpu执行时可能先执行b=20,在执行a=100,最后执行result=a*b。 在单核情况下,这种优化不会对结果造成影响 在多核情况下,后写入内存的数据未必最后写入内存 例如,cpu1 写入一个数,再将标记置为true来标记数据已经写入,cpu2通过判定这个标记来决定这个数是否已经就绪,标记先写入,数据未完成(数据没有计算完成或者没有从处理器内存刷新到主存之中),产生不良的效果。 3.JAVA内存模型 JAVA内存模型规定了一个线程如何和何时可以看到有其他线程修改过的共享变量的值,以及在必须时如何同步的访问共享变量。 当CPU要读取主存时,先将数据读取到CPU高速缓存中,再到CPU寄存器上。 当CPU回写数据时,先将内部寄存器的值写回CPU高速缓存

Unlock the Screen Programmatically

允我心安 提交于 2019-11-27 23:55:06
问题 I have a share button in the GCM notification . On click of the share button, I need to launch share intent. Everything works perfectly. Only problem that I'm facing is Lollipop lock screen feature. When I click share button from lock screen, my intent dialog appears below the lock screen and user has to unlock the screen to see the dialog. I want to unlock the screen programatically, when share button is clicked. I tried with Power Manager, But all it's wakeClock flags are deprecated and

MPI with C: Passive RMA synchronization

牧云@^-^@ 提交于 2019-11-27 21:26:15
问题 as I found no answer for my question so far and am on the edge of going crazy about the problem, I just ask the question tormenting my mind ;-) I'm working on a parallelization of a node-elimination algorithm I already programmed. Target environment is a cluster. In my parallel program I distinguish on master process (in my case rank 0) and the working slaves (every rank except 0). My idea is it, that the master is keeping track which slaves are available and send them then work. Therefore

Activity handle when screen unlocked

我的梦境 提交于 2019-11-27 18:29:21
问题 So I have my onResume command restarting a stopped thread which runs my game loop. This works perfectly for resuming the app when closed by home button or by focusing on another app. However, when you turn the screen off then on again, the activities onResume command fires right away before screen is unlocked. I need my activity to know when the screen is unlocked so it can restart the thread at the appropriate time. Has anyone had this happen before? 回答1: for detect screen on and screen off

How to customize Android's LockScreen?

久未见 提交于 2019-11-27 16:37:35
问题 I know that there is already some apps can do this, such as: WidgetLocker Lockscreen Flyscreen I want to know how to do this in my app? What classes I can use? Or what articles I should read? I don't want to change the Android's source code. And I wonder if it will be different to deal with when the screen is locked by draw pattern? 回答1: Have a look at this answer. You need to write your own home screen app which will implement the lockscreen behaviour that you require. There is sample code

How to force delete a file? [closed]

被刻印的时光 ゝ 提交于 2019-11-27 14:24:46
问题 This question exists because it has historical significance, but it is not considered a good, on-topic question for this site, so please do not use it as evidence that you can ask similar questions here. How can i force Windows XP to delete file that is currently being used by some application? 回答1: You have to close that application first. There is no way to delete it, if it's used by some application. UnLock IT is a neat utility that helps you to take control of any file or folder when it