concurrency

Synchronized block lock object question

I know the difference between synchronized method and synchronized block but I am not sure about the synchronized block part. Assuming I have this code class Test { private int x=0; private Object lockObject = new Object(); public void incBlock() { synchronized(lockObject) { x++; } System.out.println("x="+x); ...

Simulate Concurrent WCF Client Calls And Measure Response Time

I am trying to simulate X number of concurrent requests for a WCF Service and measure the response time for each request. I want to have all the requests hit the Service at more or less the same time. As the first step I spawned X number of Threads, using the Thread class, and have invoked the Start method. To synchronize all the reque...

Large array and multiple threads - spinlocks or local buffers or something else?

I have an array with 250k entities (with a size of 20 bytes) and 4 threads. Each thread modifies ~100k random entities (that means, you can't predict which entities it will touch). It can modify the same entity multiple times. Each entity gets modified up to ~10 times. The modification takes ~10-6 seconds. Each entity gets modified by m...

Make asynchronous queries synchronous

I have an underlying asynchronous out-of-order query/response system that I want to make synchronous. Queries and responses can be mapped by marking the queries with unique IDs that in turn will accompany the corresponding responses. My attempt at making it synchronous uses two ConcurrentHashMaps: one that maps from IDs to results, and ...

Java : threaded serial port read with Java.util.concurrent thread access

I'm trying to write a Java serial device driver and want to use the (new to me) java.util.concurrent package. I have one method which sends a packet then waits for an ACK. I plan to have char. reception run in a different thread. If the receive thread gets an ACK it should notify the thread with the send packet function. The receive ...

None of my AsyncTasks are executing on PostExecute

The only AsyncTask that I have that is working properly is one that handles a progressdialog for a search. None of my other AsyncTasks are getting to onPostExecute() even though the doInBackground() is completing! I am pulling my hair out because it used to work in earlier commits and doing a compare, I see no difference! A lot of the As...

ConcurrentDictionary as static cache

I'm thinking about using class (singleton) with collections implemented using ConcurrentDictionary. This class will be used as a cache implementation (asp.net / wcf). What do you think about exposing these collections explicitely from such class vs exposing just e.g. 3 methods (get,add,clear) for each of them (using safe methods from CD...

Future promises in Clojure hangs on me

When I run the following code it basically works how I intend it to, except that it hangs after the future is finished. What am I missing - some kind of "close agents/threads" call? How should I do this? (def name-to-greet (promise)) (future (println "Hello," @name-to-greet)) (print "What is your name? ") (flush) (deliver name-to-...

Ruby On Rails: How to run safe updates

I'm using RoR and I want to do concurrency safe update queries. For example when I have var user = User.find(user_id) user.visits += 1 I get the following SQL code: SELECT * FROM Users WHERE ID=1 -- find user's visits (1) UPDATE Users SET Visits=2 WHERE ID=1 -- 1+1=2 But if there are several queries taking place at the same time, ...

Why do DAOs have separate create and update methods?

I'm looking at a couple of designs for DAO interfaces. One has a single update() method, while the other has separate create() and update() methods. Assuming that it's possible to do something along the lines of 'insert otherwise update', what's the benefit of a separate create() method? Is there something to do with concurrency lurking...

Multi-node concurrency in Java

I've written a multi-threaded Java program to solve an embarrassingly parallel problem such that it utilizes all the free CPU cycles of on a multi-core CPU. I'd like to refactor my solution so that it can run on multiple nodes while still keeping the majority of the code I've already written. I've used MPI with C in the past and been t...

In pthread, how to reliably pass signal to another thread?

I'm trying to write a simple thread pool program in pthread. However, it seems that pthread_cond_signal doesn't block, which creates a problem. For example, let's say I have a "producer-consumer" program: pthread_cond_t my_cond = PTHREAD_COND_INITIALIZER; pthread_mutex_t my_cond_m = PTHREAD_MUTEX_INITIALIZER; void * liberator(void * ar...

Java ThreadPool usage

Dear StackOverflow, I'm trying to write a multithreaded web crawler. My main entry class has the following code: ExecutorService exec = Executors.newFixedThreadPool(numberOfCrawlers); while(true){ URL url = frontier.get(); if(url == null) return; exec.execute(new URLCrawler(this, url)); } The URLCrawler fetches the...

Only inserting a row if it's not already there

Hello, I had always used something similar to the following to achieve it: INSERT INTO TheTable SELECT @primaryKey, @value1, @value2 WHERE NOT EXISTS (SELECT NULL FROM TheTable WHERE PrimaryKey = @primaryKey) ...but once under load, a primary key violation occurred. This is the onl...

Entity Framework ObjectContext: Concurrency

I am trying to use an MVC application with Entity Framework and Repository pattern In this application, an end user may modify different entities data through multiple http requests during their session. (kind of wizard pages) However they do commit these modifications until a final commit button is clicked These also have the option to...

ThreadPoolExecutor policy

I'm trying to use a ThreadPoolExecutor to schedule tasks, but running into some problems with its policies. Here's its stated behavior: If fewer than corePoolSize threads are running, the Executor always prefers adding a new thread rather than queuing. If corePoolSize or more threads are running, the Executor always prefers queuing a r...

Is it unwise to have a static method be used for security validation in ASP.net?

I have a static method like this public static string DoSomethingToString(string UntrustedString) { //parse format and change string here. return newString. } Since I know that multiple calls to: static int myInt=0; public static int AddNumber() { lock(someObject) { myInt++; } return myInt; } will return an ever increasing number (...

Thread safety, lists, binding and WPF

I have a WPF ListView that is bound to a collection (List<T>). It is currently updated from the current thread which works ok. I want to move the logic for updating the list into a thread and I see some potential issues regarding thread safety and the binding of the list. Can I be assured that the binding will not be updated unless I ...

Concurrency and Networking in Flex and Actionscript

I am interested in making a RIA in Flex that will communicate with my server. The application will be downloading and uploading very often. It will need to be able to download hundreds of images over the course of its runtime. However, I have read that Flash does not support threading. Would this be a major problem if I want the UI to ...

Can two transaction run at same time in Oracle?

Hi, I have a method void SaveApplicationData() { begin transaction update insert commit transaction } if two users call this method at same time, can these two database transaction run at same time? thanks! ...