locking

What is a scalable lock?

人走茶凉 提交于 2019-12-06 00:31:05
What is a scalable lock? And how is it different from a non-scalable lock? I first saw this term in the context of the TBB rw-lock, and couldn't decide which to use. In addition, is there any rw-lock that prioritizes readers over writers? There is no formal definition of the term "scalable lock" or "non-scalable lock". What it's meant to imply is that some locking algorithms, techniques or implementations perform reasonably well even when there is a lot of contention for the lock, and some do not. Sometimes the problem is algorithmic. A naive implementation of priority inheritance, for example

JPA Pessimistic Lock Not Working

烂漫一生 提交于 2019-12-06 00:22:39
I'm using Spring Boot, JPA, Oracle 12C and a Typed Query below to select 'NEW' items to process. Once I've selected a 'NEW' item, I update its status so it's no longer eligible for selection but I'm seeing a concurrency issue with the same items getting picked up. I read here that i needed to set a 'LockModeType.PESSIMISTIC_WRITE' on the query to prevent other Threads from selecting the same row but it doesn't appear to be working. Have I missed something below or do i need another configuration to prevent concurrent threads from retrieving the same rows from my Table? Is the issue to do with

mySQL - Apply a row level lock using mysqli

假如想象 提交于 2019-12-05 23:44:16
Using PHP's mysqli how do you apply a row level lock? Row level locks stop anyone editing currently present rows that match your criteria right? but do they stop a user inserting a row which matches your criteria? Thanks if you want to lock a specific row from editing, use FOR UPDATE at the end of a SELECT query. this locks the row in your transaction and prevents other users from updating it. this only works in transactional storage engines like innodb. in answer to your questions, yes, row level locks "stop anyone editing currently present rows that match your criteria". more specifically,

How does this recursive synchronized call not deadlock?

左心房为你撑大大i 提交于 2019-12-05 23:30:50
I have a set of methods that all synchronize to the class object (can't use self, because multiple instances of this object could be used in multiple threads). Some of those methods call other methods in the class that also synchronize on the class object. Somehow this works and does not cause the deadlock I would expect it to. I would assume that testA would be blocked from running because testB already has a lock on the class object, but this apparently isn't the case. Is it something special that @synchronized is doing or is this a feature of the underlying mutex locks? Example code that

How to deal with locks (JPA)?

ε祈祈猫儿з 提交于 2019-12-05 23:28:04
问题 According to the Java Persistent/Locking wikibooks*, the best way to deal with locks is to report the Optimistic Lock Error/Exception to the user. The problem is that it's not scalable. Suppose that I have many users who are likely to cause a lock with the same action. The user does not care about the lock error message. In a nutshell : The best way is to disable all locks ? The best way is to report to the user the error lock message ? But the user must retry his action until it will work !

ASP.NET Page.Cache versus Page.Application storage for data synchronization?

左心房为你撑大大i 提交于 2019-12-05 23:25:22
Both Page.Cache and Page.Application can store an application's "global" data, shared among requests and threads. How should one storage area be chosen over the other considering scenarios of data synchronization in the multi-threaded ASP.NET environment? Looking for best practice and experienced recommendation. If the data is stable during the life of the application must always be available and must not be purged better store it in HttpApplicationState . If the data not necessarily is needed for the life of the application changes frequently can be purged if needed (for example low system

C# prevent access to all object methods from other threads

末鹿安然 提交于 2019-12-05 22:35:26
I have an object that have to be used by only a single Thread at a time. For example my Object contains 3 methods A , B and C and I want to lock the object (all the methods/attributes are locked) if a Thread access the method A . The main difficultie is that I can't modify the code of that object. I have to prevent multithreads access where i'm calling the object. My first thought was to use the singleton pattern but i didn't manage to make it work! If you can't change the code of the object, you'll have to handle the locking outside the object. For example, you could encapsulate it in another

When to LOCK TABLES in MySQL (MyISAM tables)?

ⅰ亾dé卋堺 提交于 2019-12-05 20:58:54
Is the internal locking of MySQL sufficient for a small to medium sized website? My tables are MyISAM. There might be a few hundred people concurrently hitting a specific table with SELECT'S and INSERT's. None of the INSERT/UPDATE queries would overlap. That is, no two users will be updating the same comment ID. INSERT's/UPDATE's would be one-off operations---there would be no reading of data and performing additional operations within the same query. Specifically, I am setting up a comment/chat system for my website. At worst, there might be a couple of hundred people performing a SELECT

Is this method of file locking acceptable?

回眸只為那壹抹淺笑 提交于 2019-12-05 20:46:00
We have 10 Linux boxes that must run 100 different tasks each week. These computers work at these tasks mostly at night when we are at home. One of my coworkers is working on a project to optimize run time by automating the starting of the tasks with Python. His program is going to read a list of tasks, grab an open task, mark that task as in progress in the file, and then once the task is finished mark the task as complete in the file. The task files will be on our network mount. We realize it is not recommended to have multiple instances of a program accessing the same file, but we don't

Why is fs.createReadStream … pipe(res) locking the read file?

谁都会走 提交于 2019-12-05 20:33:11
I'm using express to stream audio & video files according to this answer . Relevant code looks like this: function streamMedia(filePath, req, res) { // code here to determine which bytes to send, compute response headers, etc. res.writeHead(status, headers); var stream = fs.createReadStream(filePath, { start, end }) .on('open', function() { stream.pipe(res); }) .on('error', function(err) { res.end(err); }) ; } This works just fine to stream bytes to <audio> and <video> elements on the client. However after these requests are served, another express request can delete the file being streamed