concurrency

Multi:Threading - Is this the right approach?

Experts - I need some advice in the following scenario. I have a configuration file with a list of tasks. Each task can have zero, one or more dependencies. I wanted to execute these tasks in parallel [right now they are being executed sequentially] The idea is to have a main program to read the configuration file and load all the ta...

Actor model to replace the threading model?

I read a chapter in a book (Seven languages in Seven Weeks by Bruce A. Tate) about Matz (Inventor of Ruby) saying that 'I would remove the thread and add actors, or some other more advanced concurrency features'. Why and how an actor model can be an advanced concurrency model that replaces the threading? What other models are the 'adv...

Linq ChangeConflictException occurs when submitting DataContext changes

System.Data.Linq.ChangeConflictException: 2 of X updates failed. at System.Data.Linq.ChangeProcessor.SubmitChanges(ConflictMode failureMode) at System.Data.Linq.DataContext.SubmitChanges(ConflictMode failureMode) at PROJECT.Controllers.HomeController.ClickProc(Int32 id, String code, String n) This is what I get very often. This a...

Performance bottleneck in concurrent calls to System.currentTimeInMillis()

I suspect that calls from separate threads (>15) are having a negative effect on performance. Is there a better way to get at the system time in concurrent applications? ...

Java Thread wait() => blocked?

According to http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Thread.State.html calling wait() will result a thread to go in BLOCKED state. However this piece of code will result (after being called) in a Thread in WAITING State. class bThread extends Thread { public synchronized void run() { try { wait(); ...

Simple non-network concurrency with Twisted

Dear pythoners, I have a problem with using Twisted for simple concurrency in python. The problem is - I don't know how to do it and all online resources are about Twisted networking abilities. So I am turning to SO-gurus for some guidance. Python 2.5 is used. Simplified version of my problem runs as follows: A bunch of scientific d...

java concurrency: many writers, one reader

I need to gather some statistics in my software and i am trying to make it fast and correct, which is not easy (for me!) first my code so far with two classes, a StatsService and a StatsHarvester public class StatsService { private Map<String, Long> stats = new HashMap<String, Long>(1000); public void notify ( String key ) { ...

Why do threads spontaneously awake from wait()?

Hi, I was wondering why threads spontaneously awake from wait() in java. Is it a design decision? Is it a compromise? EDIT: (from Java Concurrency in Practice, p. 300) wait is even allowed to return "spuriously" - not in response to any thread calling notify. Further the authors state: this is like a toaster with a loose ...

How to throttle clients in a REST API

I want to limit clients to an upper limit of number of calls to my REST APIs. What should I return to inform clients that they've been throttled ? Amazon S3 is returning HTTP 503 with an error code SlowDown to inform clients. What do you advise ? ...

ConcurrentLinkedQueue$Node remains in heap after remove()

I have a multithreaded app writing and reading a ConcurrentLinkedQueue, which is conceptually used to back entries in a list/table. I originally used a ConcurrentHashMap for this, which worked well. A new requirement required tracking the order entries came in, so they could be removed in oldest first order, depending on some condition...

How can I implement a proper counter bean with EJB 3.0?

[EDIT] This question is "how do I do atomic changes to entity beans with EJB 3 and JPA 2.0". Should be simple, right? I tried to fix my code based on the answers I got so far. I'm using JBoss 6.0.0M2 with Hypersonic (just download it and call run.bat). My test case: Create 3 threads and call one of the testCounterMitLock*() 500 times i...

Handling Exceptions for ThreadPoolExecutor

I have the following code snippet that basically scans through the list of task that needs to be executed and each task is then given to the executor for execution. The JobExecutor intern creates another executor (for doing db stuff...reading and writing data to queue) and completes the task. JobExecutor returns a Future for the tasks ...

Can shared memory be read and validated without mutexes?

On Linux I'm using shmget and shmat to setup a shared memory segment that one process will write to and one or more processes will read from. The data that is being shared is a few megabytes in size and when updated is completely rewritten; it's never partially updated. I have my shared memory segment laid out as follows: -------...

Concurrent Generation of Sequential Keys

I'm working on a project which generates a very large number of sequential text strings, in a very tight loop. My application makes heavy use of SIMD instruction set extensions like SSE and MMX, in other parts of the program, but the key generator is plain C++. The way my key generator works is I have a keyGenerator class, which holds ...

atomic writes to ehcache

Context I am storing a java.util.List inside ehcache. Key(String) --> List<UserDetail> The ordered List contains a Top 10 ranking of my most active users. Problem Concurrent 3rd party clients might be requesting for this list. I have a requirement to be as current as possible with regards to the ranking. Thus if the ranking is chan...

Is it safe to lock a static variable in a non-static class?

I've got a class that manages a shared resource. Now, since access to the resource depends on many parameters, this class is instantiated and disposed several times during the normal execution of the program. The shared resource does not support concurrency, so some kind of locking is needed. The first thing that came into my mind is ha...

How to implement blocking request-reply using Java concurrency primitives?

My system consists of a "proxy" class that receives "request" packets, marshals them and sends them over the network to a server, which unmarshals them, processes, and returns some "response packet". My "submit" method on the proxy side should block until a reply is received to the request (packets have ids for identification and refer...

Can in-memory SQLite databases scale with concurrency?

In order to prevent a SQLite in-memory database from being cleaned up, one must use the same connection to access the database. However, using the same connection causes SQLite to synchronize access to the database. Thus, if I have many threads performing reads against an in-memory database, it is slower on a multi-core machine than the ...

Concurrent cartesian product algorithm in Clojure

Is there a good algorithm to calculate the cartesian product of three seqs concurrently in Clojure? I'm working on a small hobby project in Clojure, mainly as a means to learn the language, and its concurrency features. In my project, I need to calculate the cartesian product of three seqs (and do something with the results). I found t...

What is your development checklist for Java low-latency application?

I would like to create comprehensive checklist for Java low latency application. Can you add your checklist here? Here is my list 1. Make your objects immutable 2. Try to reduce synchronized method 3. Locking order should be well documented, and handled carefully 4. Use profiler 5. Use Amdhal's law, and find the sequential execution pat...