How to lock several objects?

Well, this question is way too old but, here is a compact one I figured out, both codes will end up to the same compiled statements (this and the one in the question description): lock (obj1) lock (obj2) { // your code }

Biased locking in java

Essentially, if your objects are locked only by one thread, the JVM can make an optimization and “bias” that object to that thread in such a way that subsequent atomic operations on the object incurs no synchronization cost. I suppose this is typically geared towards overly conservative code that performs locks on objects without ever … Read more

java.lang.IllegalMonitorStateException: (m=null) Failed to get monitor for

See the javadoc for Object.wait. in particular “The current thread must own this object’s monitor.” and “[throws] IllegalMonitorStateException – if the current thread is not the owner of the object’s monitor.” That is, you need to synchronize on the object you are going to call wait on. so your code should be: synchronized (available) { … Read more

What’s the least invasive way to read a locked file in C# (perhaps in unsafe mode)?

You can do it without copying the file, see this article: The trick is to use FileShare.ReadWrite (from the article): private void LoadFile() { try { using(FileStream fileStream = new FileStream( “logs/myapp.log”, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { using(StreamReader streamReader = new StreamReader(fileStream)) { this.textBoxLogs.Text = streamReader.ReadToEnd(); } } } catch(Exception ex) { MessageBox.Show(“Error loading log file: … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)