locking

Java Concurrency: CAS vs Locking [closed]

匿名 (未验证) 提交于 2019-12-03 02:52:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm reading the Book Java Concurrency in Practice . In chapter 15, they are talking about the nonblocking algorithms and the compare-and-swap (CAS) method. It is written that CAS perform much better than the locking methods. I want to ask the people who already worked with both of these concepts and would like to hear when you are preferring which one of these concepts? Is it really so much faster? For me, the usage of locks is much clearer and easier to understand and maybe even better to maintain (please correct me if I am wrong) . Should

Rails ActiveRecord: Locking down attributes when record enters a particular state

匿名 (未验证) 提交于 2019-12-03 02:51:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Wondering if there’s a plugin or best way of setting up an ActiveRecord class so that, for example, when a record enter the "published" state, certain attributes are frozen so that they could not be tampered with. 回答1: You can freeze an entire AR::B object by setting @readonly to true (in a method), but that will lock out all attributes. The way I would recommend is by defining attribute setter methods that check for the current state before passing to super: class Post < ActiveRecord::Base def author=(author) super unless self.published?

Predicate locking in PostgreSQL 9.2.1 with Serializable isolation

喜欢而已 提交于 2019-12-03 02:49:39
问题 I have been reading thoroughly the postgres documentation on transaction isolation suggested in other of my questions but I have not still managed to understand the "predicate locking" stuff. I hope somebody can enlighten me :-) According to the documentation: Predicate locks in PostgreSQL, like in most other database systems, are based on data actually accessed by a transaction That sounds good, then why is the following happening? CREATE TABLE mycustomer(cid integer PRIMARY KEY, licenses

Multiple Java threads seemingly locking same monitor?

给你一囗甜甜゛ 提交于 2019-12-03 02:46:13
In a Java threaddump I found the following: "TP-Processor184" daemon prio=10 tid=0x00007f2a7c056800 nid=0x47e7 waiting for monitor entry [0x00007f2a21278000] java.lang.Thread.State: BLOCKED (on object monitor) at org.apache.jackrabbit.core.state.SharedItemStateManager.getNonVirtualItemState(SharedItemStateManager.java:1725) - locked <0x0000000682f99d98> (a org.apache.jackrabbit.core.state.SharedItemStateManager) at org.apache.jackrabbit.core.state.SharedItemStateManager.getItemState(SharedItemStateManager.java:257) "TP-Processor137" daemon prio=10 tid=0x00007f2a7c00f800 nid=0x4131 waiting for

How can I make a non-blocking request for an exclusive lock using File#flock?

你说的曾经没有我的故事 提交于 2019-12-03 02:40:12
How Should I Request a Non-Blocking Lock? Why doesn't Ruby's File#flock work as expected when separate attempts are made to lock a file? Locking the file in a block is not the correct solution for this issue because the point is to show the behavior of locking on persistent locks. Using File#flock inside a block releases the lock when the block exits, so it doesn't demonstrate the problem properly. File#flock fails in a variety of ways, especially when requesting a non-blocking lock. Some examples follow. Failing Examples with File#flock Infinite wait when using multiple exclusive locks, since

How do I create an Activity that is visible on top of the lock screen

99封情书 提交于 2019-12-03 02:37:48
I'm receiving an incoming C2DM notification while the screen is locked. I'd like to wake up the screen and display the notification message on top of the lock screen using an Activity. I'm launching the notification Activity from my C2DM BroadcastReceiver as follows: Intent new_intent= new Intent().setClass( context, EIAlertDialog.class ); new_intent.addFlags( Intent.FLAG_ACTIVITY_CLEAR_TOP ); new_intent.addFlags( Intent.FLAG_ACTIVITY_NEW_TASK ); context.startActivity( new_intent ); and within the notification Activity's onCreate method, I wake up the screen as follows: PowerManager

synchronized block - lock more than one object

流过昼夜 提交于 2019-12-03 02:37:09
问题 I'm modelling a game where multiple players (threads) move at the same time. The information of where a player is located at the moment is stored twice: the player has a variable "hostField" that references to a field on the board and every field has an ArrayList storing the players that are currently located at this field. I'm not very happy with the fact that I have redundant information, but I found no way avoiding that without looping through a big dataset. However, when a player moves

is locking necessary for Dictionary lookup?

匿名 (未验证) 提交于 2019-12-03 02:00:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: lock(dictionaryX) { dictionaryX.TryGetValue(key, out value); } is locking necessary while doing lookups to a Dictionary ? THe program is multithreaded, and while adding key/value to dict. dict is being locked. 回答1: Locking is only needed when you are synchronizing access to a resource between threads. As long as there are not mulitple threads involved then locking is not needed here. In the context of updating and reading the value from multiple threads, yes a lock is absolutely necessary. In fact if you're using 4.0 you should consider

Java thread dump: Difference between “waiting to lock” and “parking to wait for”?

邮差的信 提交于 2019-12-03 01:53:37
问题 In a Java thread dump, you can see locks mentioned within stack traces. There seems to be three kinds of information: 1: - locked <0x00002aab329f7fa0> (a java.io.BufferedInputStream) 2: - waiting to lock <0x00002aaaf4ff6fa0> (a org.alfresco.repo.lock.LockServiceImpl) 3: - parking to wait for <0x00002aaafbf70bb8> (a java.util.concurrent.SynchronousQueue$TransferStack) 1: The thread has obtained a lock on object 0x00002aab329f7fa0. 2&3: Seem to say that the thread is waiting for the lock on

Find out who is locking a file on a network share

一个人想着一个人 提交于 2019-12-03 01:32:49
问题 I want to known who is locking a file on a network share. Here is the problem : the network share is on a NAS, so I can't log on. I need a tool to find out remotely who is locking the file. It is not practical to reboot the NAS every time, because there are several users. Handle.exe, Process Explorer and PsFile seems to be limited to files on the local machine, so they don't work for me. 回答1: Just in case someone looking for a solution to this for a Windows based system or NAS: There is a