concurrency

Resources on the upcoming fork-join framework

I'm looking for well organized information sources about how the upcoming jsr166y (fork-join, fences) and extras166y (ParallelArray, etc.) can be used - something from tutorial to expert level. ...

Multithread search operation (? Callable versus Runnable, FutureTask, Thread ?) in Java

I have a method that takes an array of queries, and I need to run them against different search engine Web API's, such as Google's or Yahoo's. To optimize this process, I thought of creating a thread for each query, and then joining them all at the end, since my application can only continue after I have the results of every query. My st...

Design considerations for an adaptive thread pool in Java

I would like to implement a thread pool in Java, which can dynamically resize itself based on the computational and I/O behavior of the tasks submitted to it. Practically, I want to achieve the same behavior as the new Thread Pool implementation in C# 4.0 Is there an implementation already or can I achieve this behavior by using mostl...

How to make all AJAX calls sequential?

I use jQuery. And I don't want concurrent AJAX calls on my application, each call must wait the previous before starting. How to implement it? There is any helper? UPDATE If there is any synchronous version of the XMLHttpRequest or jQuery.post I would like to know. But sequential != synchronous, and I would like an asynchronous and sequ...

What's Java's equivalent of .Net's Interlocked class?

How do I modify an int atomically and thread-safely in Java? Atomically increment, test & set, etc...? ...

How do I organize multithreaded access to a graph?

I'm elaborating over a problem which seems hard to me and I'm not expecting a simple solution, but maybe there are proven practices or further reading that might make this easier. I'm pretty sure that the general problem pops up in many applications (for example garbage collection or transactional databases). My application has a graph ...

NHibernate Optimistic Concurrency

I'm investigating optimistic concurrency in NHibernate. I have a scenario that is very similar to what is being described here: http://weblogs.asp.net/stefansedich/archive/2008/10/01/set-the-value-of-a-version-column-in-nhibernate-manually.aspx Would you recommend going with the proposed solution in this blog post? Thanks ...

Concurrent file write

Hi, how to write to a text file that can be accessed by multiple sources (possibly in a concurrent way) ensuring that no write operation gets lost? Like, if two different processes are writing in the same moment to the file, this can lead to problems. The simples solution (not very fast and not very elegant) would be locking the file wh...

Chain Locking via Lock

Hi Guys, It is mentioned that one of the advantages of Lock (java.util.concurrent.locks.Lock) over intrinsic lock is that Lock facilitates "chain locking". Chain locking being, hold a lock for A, then acquire B, after acquiring B release A and then acquire C ... I am just curious, have you guys encountered any situation in which the u...

What object should I lock on when I am passing a Collection<Foo> into a separate class ?

Please refer to UML The Connection class's constructor initializes its foos member via foos = Collections.synchronizedList( new ArrayList<Foo>(10) ); When Connection#start() is invoked, it creates an instance of Poller (while passing the foos reference into Poller's constructor) & Poller is started (Poller is a Runnable). Question: ...

How do I call some blocking method with a timeout in Java?

Is there a standard nice way to call a blocking method with a timeout in Java? I want to be able to do: // call something.blockingMethod(); // if it hasn't come back within 2 seconds, forget it if that makes sense. Thanks. ...

Directed notifyAll()

Hi Guys, A question if I may. Lets suppose that my main thread creates 3 threads. These 3 threads call wait() on a certain object. Then the main thread calls notifyAll() for the same object. How can I ensure than thread2, and only thread2, proceeds while thread1 and thread3 simply ignore the notification and go back to waiting state? ...

only update 1 column with linq

Hi, I'm using linq to retrieve a row from a table in the database. Now I only update 1 column. Then I update it back into the database. this goes well, except for the times any of the other fields is changed by another process/thread/user In that case I get an exception (optimistic concurrency), telling me to look out, values have been...

Publishing Concurrent Objects

I'm interested in techniques people use to publish information and changes to data structures that are being shared across multiple threads without losing much concurrency. In my personal experience I come across the single writer/multiple readers quite often, where a single thread is updating an object, but multiple threads are reading ...

How do I take ownership of an abandoned boost::interprocess::interprocess_mutex?

Hi, My scenario: one server and (some clients (though not many). The server can only respond to one client at a time, so they must be queued up. I'm using a mutex (boost::interprocess::interprocess_mutex) to do this, wrapped in a boost::interprocess::scoped_lock. The thing is, if one client dies unexpectedly (i.e. no destructor runs) ...

Should I use thread local storage for variables that only exist in a {class,method}?

I am implementing a relatively simple thread pool with Python's Queue.Queue class. I have one producer class that contains the Queue instance along with some convenience methods, along with a consumer class that subclasses threading.Thread. I instantiate that object for every thread I want in my pool ("worker threads," I think they're ...

Java: Class entirely run in second thread / IllegalMonitorStateException

Hello When you want a certain task to be executed by another thread, you can extend Thread or implement Runnable. I've made an attempt to create a class which runs a class entirely in the second thread. This means that you can call anyMethod() which returns immediately and which is executed by the second thread. Here is my attempt:...

How to deal with concurrent updates in databases ?

What's the common way to deal with concurrent updates in an SQL database ? Consider a simple SQL schema(constraints and defaults not shown..) like create table credits ( int id, int creds, int user_id ); The intent is to store some kind of credits for a user, e.g. something like stackoverflow's reputation. How to deal with con...

Swing: Passing a value back to the UI from a scheduled thread

I have a system tray UI in Java that requires a schedule database poll. What is the best method for spawning a new thread and notifying the UI? I'm new to Swing and it's threading model. ...

CCR: Best practice for handling errors using causalities

Having a complex sequence of tasks, implementing error handling can quickly bloat the code when using try/catch blocks and stuff like Choice receivers on PortSet<ActualResult, Exception> for every little task. Thankfully the CCR seems to offer a mechanism to handle exceptions in a more general way for a graph of tasks: causalities. A ty...