concurrency

Which thread will get the lock?

suppose we have multi processor machine and multi threaded application. If two threads have access to a synchronized method and they got executed at the same time which thread will gets the lock? or what will happen? Thanks ...

Reference counting in Java

I have a system that keeps running out of disk space because that garbage collector doesn't free the objects that hold the file handles fast enough. (Files are created and deleted all the time, but since the process still has an open file handle, the OS keeps it on the disk). The objects are shared, so a simple try { ... } finally { clo...

Concurrent execution in apache/mod_php?

Hello, i am currently working on an MVC webframework with a very special feature. Layouts defined in XML files are seperated into content blocks that can be arranged/cached/loaded individually. Every content block (this could be e.g. the footer which is re-used on several pages) has some sort of Controller of its own. I call it Blockco...

How to handle concurrency clash in ASP.Net MVC using post-redirect-get?

I use a post-redirect-get (PRG) pattern to save an entity in ASP.Net MVC 2. The controller methods are 'Save' (inserts or updates database) and 'Edit' (retrieves user input). In 'Save', I do modification check before saving by checking a 'version' column of the entity. If someone else has modified the entity, the 'version' column will no...

How to visualize the behavior of many concurrent multi-stage processes?

Suppose I've got a ton (a continuous stream) of requests to process, and each request has several stages. For example: "connecting to data source", "reading data from data source", "validating data", "processing data", "connecting to data sink", "writing result to data sink". Which visualization methods or even tools fit well to visuali...

Is it possible to do a 'dirty update' ?

I have a SPROC that runs every hour. This SPROC calculates the popularity of a users artwork and updates the popularity column on the main artwork table. This is the same table where users are writing to it each time they upload a new artwork. The problem is, this sproc keeps getting deadlocked with another transaction. Considering I ...

Memory barriers and coding style over a Java VM

Suppose I have a static complex object that gets periodically updated by a pool of threads, and read more or less continually in a long-running thread. The object itself is always immutable and reflects the most recent state of something. class Foo() { int a, b; } static Foo theFoo; void updateFoo(int newA, int newB) { f = new Foo(); ...

Dalvik and out-of-order writes

Java specification allows the compiler and the VM to reorder memory writes in the interest of efficiency. Does the Dalvik VM take concrete advantage of this ? Disclaimer : I have no intention of relying on order even if Dalvik does not do it (besides the compiler may do it too), but it would be nice to know. ...

What are the ways not to wait for execution of a code block or a method?

What are the correct ways/practice/implementation/strategies (or whatever we call it as) for not to wait for code block/method to finish execution in Java? Assume the following method: private void myMethod() { // Some lines of code here ..... ..... ..... anotherMethod(); // or this could be a code block ...

How to Prevent Sql Server Jobs to Run simultaneously

I have some jobs for example : job1, executing every 2 minutes job2, executing every 10 minutes job3, executing every 15 minutes now there is a problem. jobs may occur simultaneously and cpu usage go to 100%; is there a solution? remind that I need jobs to run approximately in their appropriate period. thanks. ...

Which parallel sorting algorithm has the best average case performance?

Sorting takes O(n log n) in the serial case. If we have O(n) processors we would hope for a linear speedup. O(log n) parallel algorithms exist but they have a very high constant. They also aren't applicable on commodity hardware which doesn't have anywhere near O(n) processors. With p processors, reasonable algorithms should take O(n/p l...

BlockingCollection + UI Thread

I've followed this tutorial, to create a priority queue and wrapped it with a blocking collection. I've got a DataGrid which I've wired to the underlying priority queue which emits change events. I can add items to the collection from the UI thread w/out a hitch, and it blocks when the buffer is full as it's supposed to. Now how do I co...

Getting Dictionary<K,V> from ConcurrentDictionary<K,V> in .NET 4.0

I'm parallelizing some back-end code and trying not to break interfaces. We have several methods that return Dictionary and internally, I'm using ConcurrentDictionary to perform Parallel operations on. What's the best way to return Dictionary from these? This feels almost too simple: return myConcurrentDictionary.ToDictionary(kvp => ...

How do I use rand_r and how do I use it in a thread safe way?

I am trying to learn how to use rand_r, and after reading this question I am still a little confused, can someone please take a look and point out what I'm missing? To my understanding, rand_r takes a pointer to some value (or a piece of memory with some initial value) and use it to generate new numbers every time it is called. Each thre...

What are the advantages of using an ExecutorService?

What is the advantage of using ExecutorService over running threads passing a Runnable into the Thread constructor? ...

Is it safe to access EJB home object from multiple threads?

Hello guys, I have read this thread: J2EE/EJB + service locator: is it safe to cache EJB Home lookup result ? I use the same approach, i.e. I obtain EJB home object for my entity bean and cache it in a servlet. My question is: is it safe to share this object between multiple threads? From EJB 2.1 spec I found only that concurrent call...

Locking on Strings

2 Questions: str field is shared between two instance of A type [line 2] What's implications according to following code ? class A implements Runnable { String str = "hello"; // line 2. public void run(){ Synchronized(str){ System.out.println(str+" "+Thread.currentThread().getName()); Thread.sleep(100); System.out.println(str+" "...

Behavior of the FileChannel to RandomAccessFile

I have one use-case where my multiple threads are writing data to same file channel (pooled), and each thread has offset in the file from where they can start writing till the length of the data to be written. So when I ask the file channel from pool it will open the channel in "rw" mode if it already not opened and will return that file...

Does SoapHttpClientProtocol.BeginInvoke hold a thread?

Does SoapHttpClientProtocol.BeginInvoke hold onto a worker thread while waiting for i/o? ...

Producer-Consumer model - binary semaphore or mutex??

This is mainly about the understanding of the concept, which confuses me. Mutex means that one thread takes the control of the access of shared resource, performs operations and unlocks it, then only other thread can gain access to lock while binary semaphore is like a thread can gain access to the shared resource but gaining acces...