locking

Using lock with Threading.Timer

隐身守侯 提交于 2019-11-30 10:49:43
问题 I have a Windows Service application which uses a Threading.Timer and a TimerCallback to do some processing at particular intervals. I need to lock down this processing code to only 1 thread at a time. So for example, the service is started and the first callback is triggered and a thread is started and begins processing. This works ok as long as the processing is completed before the next callback. So say for instance the processing is taking a little longer than usual and the TimerCallback

Using WITH NOLOCK Table Hint in Query Using View - Does it Propagate Within the View?

别来无恙 提交于 2019-11-30 10:40:58
If a "WITH NOLOCK" query hint is used on a View in SQL Server, does it propagate that hint to the view definition itself, even if NOLOCK is NOT used for the raw tables in the View definition? The reason to need this is that sometimes the support staff wants to do huge time-consuming queries but would rather not force this lock on all queries using the view within the application itself. Yes, NOLOCK will propagate to the tables used by the view definition (at least in SQL Server 2005). See Table Hints in MSDN: In SQL Server 2005, all lock hints are propagated to all the tables and views that

What is wrong with this solution to locking and managing locked exceptions?

我是研究僧i 提交于 2019-11-30 09:48:57
My objective is a convention for thread-safe functionality and exception handling within my application. I'm relatively new to the concept of thread management/multithreading. I am using .NET 3.5 I wrote the following helper method to wrap all my locked actions after reading this article http://blogs.msdn.com/b/ericlippert/archive/2009/03/06/locks-and-exceptions-do-not-mix.aspx , which was linked in response to this question, Monitor vs lock . My thought is that if I use this convention consistently in my application, it will be easier to write thread-safe code and to handle errors within

Can ToArray() throw an exception?

∥☆過路亽.° 提交于 2019-11-30 09:07:50
While the answer to this question is excellent, it implies that you should surround calls to List.ToArray() in a lock for concurrency. this blog post also implies that it could fail catastrophically (but rarely). I typically use ToArray rather than a lock in when enumerating Lists or other collections in order to avoid the "Collection Modified, Enumeration may not complete" exception. This answer and the blog post have called that assumption into question. The documentation for List.ToArray() does not list any exceptions, so I have always assumed that it will always complete (albeit maybe with

Read-Write lock with GCD

社会主义新天地 提交于 2019-11-30 09:03:42
My application makes heavy use of GCD, and almost everything is split up in small tasks handled by dispatches. However, the underlying data model is mostly read and only occasionally written. I currently use locks to prevent changes to the critical data structures while reading. But after looking into locks some more today, I found NSConditionLock and some page about read-write locks. The latter is exactly what I need. I found this implementation: http://cocoaheads.byu.edu/wiki/locks . My question is, will this implementation work with GCD, seeing that it uses PThreads? It will still work.

Android - Activation of the system key lock (aka lock screen)

一笑奈何 提交于 2019-11-30 09:00:40
I have to activate android's system key lock (the one you get when you press the power off / hang up button). See here: I already browsed the docs but everything I found was PowerManager and KeyguardManager . Both seem not to be the solution :-(. So, does everyone know how to achieve that from a android application? (If special permissions are required, that is no problem but changing the device's settings is not a solution...) EDIT : Or does someone know that this is definitely not possible at all? Btw. craigs solution with sending keys does not work anymore (see comments). I have been

Java keeps lock on files for no apparent reason

你离开我真会死。 提交于 2019-11-30 08:53:25
Despite closing streams in finally clauses I seem to constantly run into cleaning up problems when using Java. File.delete() fails to delete files, Windows Explorer fails too. Running System.gc() helps sometimes but nothing short of terminating the VM helps consistently and that is not an option. Does anyone have any other ideas I could try? I use Java 1.6 on Windows XP. UPDATE: FLAC code sample removed, the code worked if I isolated it. UPDATE: More info, this happens in Apache Tomcat, Commons FileUpload is used to upload the file and could be the culprit, also I use Runtime.exec() to execute

PDO, mysql, transactions and table locking

試著忘記壹切 提交于 2019-11-30 08:34:34
For fun I am replacing the mysqli extension in my app with PDO. Once in awhile I need to use transactions + table locking. In these situations, according to the mysql manual, the syntax needs to be a bit different. Instead of calling START TRANSACTION, you do it like so... SET autocommit=0; LOCK TABLES t1 WRITE, t2 READ, ...; ... do something with tables t1 and t2 here ... COMMIT; UNLOCK TABLES; ( http://dev.mysql.com/doc/refman/5.0/en/lock-tables-and-transactions.html ) My question is, how does this interact with PDO::beginTransaction? Can I use PDO::beginTransaction in this case? Or should I

Limiting the number of threads executing a method at a single time

断了今生、忘了曾经 提交于 2019-11-30 08:33:14
We have a situation where we want to limit the number of paralell requests our application can make to its application server. We have potentially 100+ background threads running that will want to at some point make a call to the application server but only want 5 threads to be able to call SendMessage() (or whatever the method will be) at any one time. What is the best way of achieving this? I have considered using some sort of gatekeeper object that blocks threads coming into the method until the number of threads executing in it has dropped below the threshold. Would this be a reasonable

Why did Java and C# add intrinsic lock to every object?

谁说胖子不能爱 提交于 2019-11-30 08:17:31
Making every object lockable looks like a design mistake: You add extra cost for every object created, even though you'll actually use it only in a tiny fraction of the objects. Lock usage become implicit, having lockMap.get(key).lock() is more readable than synchronization on arbitrary objects, eg, synchronize (key) {...} . Synchronized methods can cause subtle error of users locking the object with the synchronized methods You can be sure that when passing an object to a 3rd parting API, it's lock is not being used. eg class Syncer { synchronized void foo(){} } ... Syncer s = new Syncer();