concurrency

How can I allow concurrent reads but block all access during a write on an object in Java?

If I have a data structure in a multithreaded application that I want to access simultaneously with reads while it's not altered, but disallow both read and write access to other threads while one is writing? For simplicity, let's say I have an array and two methods read() and write(): int[] rgData; // ... int read(int ix) { retu...

MySQL: Correctness in the face of heavy concurrency (SELECT ... FOR UPDATE)

Hi everybody, I'm running a website where users can adopt virtual pets. There is a per-user adoption limit on each pet. So, for example, you can adopt one of our pets a maximum of 10 times. At the moment we do something like this: CREATE TABLE `num_adopted` ( `petid` int(11) NOT NULL, `userid` int(11) NOT NULL, `total` int(11) un...

SET NOCOUNT ON usage

Inspired by this question where there are differing views on SET NOCOUNT... General accepted best practice (I thought until this question) is to use SET NOCOUNT ON in triggers and stored procedures in SQL Server. We use it everywhere and a quick google shows plenty of SQL Server MVPs agreeing too. MSDN says this can break a .net SQLDat...

How are mutexes implemented?

Are some implementations better than others for specific applications? Is there anything to earn by rolling out your own? ...

Java email sending queue - fixed number of threads sending as many messages as are available

I'm writing a message processing application (email) that I want to have an outgoing queue. The way I've designed this is having a singleton queue class, ThreadedQueueSender, backed by an Executor Service and a BlockingQueue. Additionally, a thread pool of javax.mail.Transport objects is used to obtain and release connections to the outg...

How to build a server that can handle 20.000 concurrenct connections?

It's hard for me to go into exact detail on what the server needs to do (due to NDAs and what not), but it should be sufficient to say that it needs to handle a lightweight binary protocol with many concurrent connected users, ~20.000 is where we have a pretty decent estimate. Note that clients won't be sending/receiving constantly, but...

How to manage object life time using Boost library smart pointers?

Hi, There is a scenario that i need to solve with shared_ptr and weak_ptr smart pointers. Two threads, thread 1 & 2, are using a shared object called A. Each of the threads have a reference to that object. thread 1 decides to delete object A but at the same time thread 2 might be using it. If i used shared_ptr to hold object A's refere...

Why would invokeAll() not return?

I have roughly this code: ExecutorService threader = Executors.newFixedThreadPool(queue.size()); List futures = threader.invokeAll(queue); I debug this and invokeAll doesn't seem to return until all the threads in the Queue are finished. Any reasons why this is happening. ...

Linq caching data values - major concurrency problem?

Here's a little experiment I did: MyClass obj = dataContext.GetTable<MyClass>().Where(x => x.ID = 1).Single(); Console.WriteLine(obj.MyProperty); // output = "initial" Console.WriteLine("Waiting..."); // put a breakpoint after this line obj = null; obj = dataContext.GetTable<MyClass>().Where(x => x.ID = 1).Single(); // same as before, b...

How to Tell if a Thread Pool is Idle in Java

I have a thread pool created using java.util.concurrent.ThreadPoolExecutor Is there anyway I can wait till the pool is idle? By which I mean all the threads are not running and nothing is waiting in the queue. I searched the web and all the solutions don't work for me. For example, I don't want shutdown the pool so awaitTerminatio...

Log output of multiprocessing.Process

Is there a way to log the stdout output from a given Process when using the multiprocessing.Process class in python? ...

How do I get visual studio to not wait on temporarily blocked tests?

I'm relatively new to unit testing, and trying it on my personal projects. I want to unit test some concurrent methods (futures which run actions in the thread pool). To avoid the test method finishing before the thread pooled action, I'm blocking the test. Here is the actual blocking code: Private Shared Function BlockOnFuture(ByVal fu...

How to check if a table is locked in sql server

I have a large report I am running on sql server. It takes several minutes to run. I don't want users clicking run twice. Since i wrap the whole procedure in a transaction, how do I check to see if the table is locked by a transaction? If so I would want to return an error message saying "report generating, please try again in a few min...

Linux: Is this a correct way to run scripts in parallel?

Hello! I want to update a large amount of SVN-versioned projects at once, using a script. It takes very long when running update jobs one by one. So I tried to run the jobs in parallel. It seems to work, however I'm not sure if it's done correctly. Perhaps there are concurrency issues I didn't think of? Please take a look at the scrip...

ScheduledExecutorService with variable delay

Suppose I have a task that is pulling elements from a java.util.concurrent.BlockingQueue and processing them. public void scheduleTask(int delay, TimeUnit timeUnit) { scheduledExecutorService.scheduleWithFixedDelay(new Task(queue), 0, delay, timeUnit); } How can I schedule / reschedule the task if the frequency can be changed dyna...

Why does Executors.newCachedThreadPool throw java.util.concurrent.RejectedExecutionException during submit

Number of tasks (threads) submitted is also not huge in this test scenario. ...

Avoiding multiple repopulations of the same cache region (due to concurrency)

Hello I have a high traffic website and I use hibernate. I also use ehcache to cache some entities and queries which are required to generate the pages. The problem is "parallel cache misses" and the long explanation is that when the application boots and the cache regions are cold each cache region is being populated many times (inste...

mysql isolation levels

I'm a bit confused by the documentation here. I have a transaction, which start transaction does some updates does some selects does some more updates commit I want my selects at step 3 to see the results of updates in step 2 but I want to be able to roll back the whole thing. read committed seems to imply that selects only show ...

Servlet concurrency/synchronization in Tomcat?

Is there a recommended way to synchronize Tomcat Servlet instances that happen to be competing for the same resource (like a file, or a database like MongoDB that isn't ACID)? I'm familiar with thread synchronization to ensure two Java threads don't access the same Java object concurrently, but not with objects that have an existence ou...

Getting starting with Parallel programming.

Hi guys, So it looks like multicore and all its associated complications are here to stay. I am planning a software project that will definitely benefit from parallelism. The problem is that I have very little experience writing concurrent software. I studied it at University and understand the concepts and theory very well but have zer...