locking

Select for update skip locked from JPA level

做~自己de王妃 提交于 2019-12-21 07:16:31
问题 In my application - Oracle with JPA (EclipseLink), I'm using the following expression to lock the subset of the records in some tables: select * from MY_TABLE where MY_CONDITIONS for update skip locked I run it throughout native query, but I have to write that query for all required entities. Is there any way to skip locked records using pure JPA? Can I implement my own locking policy? I don't mind changing JPA provider but I want to use JPA API. 回答1: Hibernate provides the UPGRADE_SKIPLOCKED

Non-busy blocking Queue Implementation in C

南楼画角 提交于 2019-12-21 05:58:07
问题 I am trying to implement a queue in C that causes a process to non-busy wait until there is an element in the queue to consume. I have tried two different things to try to achieve this. The first problem I have is if the enqueue/dequeue operations have if conditionals to check the bounds( if (q->count == QUEUESIZE) ), the call to sem_wait will return immediately because no other process has obtained a lock. If I change the conditional to while (q->count == QUEUESIZE), I believe the consumer

How does JVM make sure only one thread can acquire the lock of an object?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-21 05:37:13
问题 Most of us know that whenever thread accesses a synchronized block of a object, JVM gives the lock of that object to the thread. How does JVM make sure that only one thread can have access to a lock of an object? 回答1: The JVM uses some locking feature provided by the operating system, like a semaphore object. So the question now becomes how the operating system does it. Usually there is hardware support for these things. The CPU may offer a compare-and-set instruction which, while executing,

Lock analyser for Java application

余生颓废 提交于 2019-12-21 05:27:10
问题 I have two versions of a Java application which use different concurrency logic. I want to analyze and compare their performance (such amount of time a lock was acquired etc.) so that I can use the better one. I found out a tool IBM Lock Analyzer for Java but it is neither open source nor JDK version independent. It requires an IBM®-supplied Java™ SDK or JRE. Another tool also from IBM is Multicore Software Development Kit and has the following problem "The testing and analysis tool of MSDK

How to call a python function from a foreign language thread (C++)

纵然是瞬间 提交于 2019-12-21 05:12:09
问题 I am developing a program that use DirectShow to grab audio data from media files. DirectShow use thread to pass audio data to the callback function in my program, and I let that callback function call another function in Python. I use Boost.Python to wrapper my library, the callback function : class PythonCallback { private: object m_Function; public: PythonCallback(object obj) : m_Function(obj) {} void operator() (double time, const AudioData &data) { // Call the callback function in python

MySQL atomic operations and table locking

前提是你 提交于 2019-12-21 04:32:08
问题 I have a website where users can purchase tickets, but ticket quantities are usually limited and go quickly. I'm trying to implement an escrow system such that a user can click that they want x number of tickets, at which point I will put them in an escrow state. That gives them several minutes to enter their credit card information and complete the purchase. I have three relevant tables: events, tickets, and escrow. A row in the events table describes the event itself, including the maximum

SQL Server locks explained

試著忘記壹切 提交于 2019-12-21 03:55:18
问题 Below is a list of locks that SQL Server 2000 is meant to support. I am a bit confused as to what the "intent" locks actually mean. I've looked around on the Web and the answers seem to be a bit cryptic. Further to getting an answer to my specific question, I am hoping to use this question as a Wiki for what each lock means and under what circumstances that type of lock will be acquired. Shared (S) Update (U) Exclusive (X) Intent intent shared (IS) intent exclusive (IX) shared with intent

C# method to lock SQL Server table

雨燕双飞 提交于 2019-12-21 03:50:36
问题 I have a C# program that needs to perform a group of mass updates (20k+) to a SQL Server table. Since other users can update these records one at a time via an intranet website, we need to build the C# program with the capability of locking the table down. Once the table is locked to prevent another user from making any alterations/searches we will then need to preform the requested updates/inserts. Since we are processing so many records, we cannot use TransactionScope (seemed the easiest

Query whether Python's threading.Lock is locked or not

做~自己de王妃 提交于 2019-12-21 03:37:05
问题 I have a thread I am running (code below) which launches a blocking subprocess. To ensure that other threads do not launch the same subprocess, I have a lock around this subprocess.call call. I also want to be able to terminate this subprocess call, so I have a stop function which I call from somewhere else. In the event that the subprocess is stopped prematurely, I want to release the lock as well, which is what the below code does: class SomeThread(threading.Thread): def run(self): aLock

How to lock a variable used in multiple threads

南笙酒味 提交于 2019-12-21 03:31:41
问题 I have asked a question badly over here Lock on a variable in multiple threads so for clarity I am going to ask it here and hope I can ask it correctly. classA creates instance of classB has methodA that can update & uses classB's myVar has methodB that can update & uses classB's myVar classB has a variable myVar methodA and methodB can both run in separate threads (called in new threads from main). How do I ensure this is thread safe? 回答1: Use the lock keyword to guard code that can be