locking

How do I get hibernate to generate Oracle's FOR UPDATE WAIT 10 syntax

a 夏天 提交于 2019-12-10 00:10:47
问题 I have a line of code like this: final Foo foo = (Foo)session.get( Foo.class, id, LockMode.UPGRADE ); This generates a SELECT .. FOR UPDATE . However, I'm only willing to wait for 10 seconds to obtain the lock and there for I would like a SELECT .. FOR UPDATE WAIT 10 . How can I get hibernate to generate this? 回答1: The answer is to use the LockOptions class with SetTimeout() rather than LockMode. For this, we upgraded to Hibernate 3.6 only to find it is broken for Oracle. 回答2: AFAIK, you can

Java thottling mechanism

扶醉桌前 提交于 2019-12-09 20:41:37
问题 Update : I'm on Java 1.6.34 with no chance of upgrading to Java 7. I have a scenario where I am only allowed to call a method 80 times per minute. It's actually a service API written by a 3rd party, and it "shuts down" (ignores calls) its API if you call it too many times: public class WidgetService { // Can only call this method 80x/min, otherwise it // it just doesn't do anything public void doSomething(Fizz fizz); } I'd like to write an ApiThrottler class that has a boolean canRun() method

Table exclusive lock with JPA

邮差的信 提交于 2019-12-09 17:48:32
问题 Is it possible to lock exclusively entire table with JPA in database agnostic way (without using native queries for instance)? So far I saw only EntityManager.lock(*) but this locks only given record. 回答1: I don't think this is supported by JPA natively - you always lock single entity or every entity which is a result from a query. Inserts are always allowed as they are new entities. You may either use native query to trigger a lock using SQL supported by your DB server, or you need to lock

How do you stop a user-instance of Sql Server? (Sql Express user instance database files locked, even after stopping Sql Express service)

瘦欲@ 提交于 2019-12-09 17:48:14
问题 When using SQL Server Express 2005's User Instance feature with a connection string like this: <add name="Default" connectionString="Data Source=.\SQLExpress; AttachDbFilename=C:\My App\Data\MyApp.mdf; Initial Catalog=MyApp; User Instance=True; MultipleActiveResultSets=true; Trusted_Connection=Yes;" /> We find that we can't copy the database files MyApp.mdf and MyApp_Log.ldf (because they're locked) even after stopping the SqlExpress service, and have to resort to setting the SqlExpress

JVM SafePointStatistics - Can anyone help interpret it

对着背影说爱祢 提交于 2019-12-09 17:39:10
问题 On enabling the +XX:PrintSafePointStatistics , I see a dump on the stdout in the following format. Can anyone please help me interpret the column names or the JVM guide which explains this properly? The JVM specification guide does not seem to be covering the meaning of the headers and its explanation at all. @400000005175823c18c9d534 16762.525: GenCollectForAllocation [ 973 0 0 ] [ 0 0 0 5 53 ] 0 @400000005175823c18c9f08c 16762.586: CMS_Initial_Mark [ 973 0 1 ] [ 0 0 0 4 24 ] 0

What does 'Mutex lock' exactly do?

给你一囗甜甜゛ 提交于 2019-12-09 17:07:15
问题 You can see an interesting table at this link. http://norvig.com/21-days.html#answers The table described, Mutex lock/unlock 25 nanosec fetch from main memory 100 nanosec Nanosec? I surprised because mutex lock is faster than fetch data from memory . If so, what mutex lock exactly do? And what does Mutex lock mean at the table? 回答1: The article you linked does not mentioned the architecture, but judging by mentions of L1 and L2 cache it's Intel. If this is so, then I think that by mutex they

Lock on a variable in multiple threads

☆樱花仙子☆ 提交于 2019-12-09 16:55:25
问题 I am very new to C# and I wanted to ask if I have this situation in MULTI THREADS (pseudo code): public class ClassA { ClassB c = new ClassB(); public void someMethod() { c.myVar = 1; // Some other stuff c.myVar = 0; } } public class ClassB { internal int myVar; public void MethodA() { if(myVar = 1) myVar = 0; } } If someMethod() and MethodA() can be active in separate threads, then MethodA() could evaluate the if statement as true; but before it sets myVar = 0 , someMethod() sets myVar = 0

Concurrent object locks based on ID field

醉酒当歌 提交于 2019-12-09 15:57:12
问题 I have a producer/consumer process. The consumed object has an ID property (of type integer), I want only one object with the same ID to be consumed at a time. How can I perform this ? Maybe I can do something like this, but I don't like it (too many objects created while only one or two with the same ID a day can be consumed and the lock(_lockers) is a bit time consuming : private readonly Dictionary<int,object> _lockers = new Dictionary<int,object>(); private object GetLocker(int id) { lock

Triggers and table lock in MySQL

时间秒杀一切 提交于 2019-12-09 14:32:51
问题 Scenario: I have some triggers that keep track of number of records of one table, together with other useful information. These triggers are fired upon add/delete/update on this table and take care of writing this information in another complementary table. Now these triggers will run on a multi-threaded environment where possibly I may have concurrent access to tables. I wish I could make something like this, but it is forbidden ( ERROR: Error Code: 1314. LOCK is not allowed in stored

How to synchronize method access(thread safe) by using Lock and delegates [closed]

我的未来我决定 提交于 2019-12-09 13:58:40
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 4 months ago . Assume we have a method like this public static void method(string param) { ** critical section ** // There are a lot of methods calls // switch cases // if conditions // read and write in dictionary // new class initiations ** critical section ** } how we can make it thread safe