concurrency

Should I put my ThreadLocals in a spring-injected singleton?

Several people (eg at serverside http://www.theserverside.com/news/thread.tss?thread_id=41473) suggest that using ThreadLocal objects is as bad as using global variables. I imagine this is true if you make them public static variables. The problem then is that it can be hard to tell where it is used, where it's changed, etc. In my sprin...

Is the MailboxProcessor type a replacement for locks?

I have been slowly examining all of the features that F# brings to the table. One that has particularly piqued my interest is the MailboxProcessor. The equivalent of this in C# would most likely use locks. Can we consider the MailboxProcessor as a replacement for locks? In the following example, am I doing anything particularly naive o...

Guarantee order of messages posted to mailbox processor

I have a mailbox processor which receives a fixed number of messages: let consumeThreeMessages = MailboxProcessor.Start(fun inbox -> async { let! msg1 = inbox.Receive() printfn "msg1: %s" msg1 let! msg2 = inbox.Receive() printfn "msg2: %s" msg2 let! msg3 = inbox.Recei...

Concurrency in web applications

So recently there has been a lot of emphasis by almost all platform providers to provide new tools/language constructs for better concurrency. And that is also one of the reasons why a lot of ideas from functional programming languages are being integrated into mainstream languages like C#, Java etc. Even though these make a lot of sens...

What is equivalent of the C# lock statement in PHP?

For concurrency and ensuring the integrity of the data, how would you obtain a mutual-exclusion lock for a given object? Would you need to use locking within the database, or a file, or does PHP support something like this? ...

Concurrent loading of .js files via https

We're looking at splitting our .js to be served from two domains with the intent that that would enable concurrent loading. Question: Can we a) use subdomains for that purpose and b) will that concurrent loading also hold true over https? For instance, we'd like to request two files as such: https://www.example.com/firstfile.js https...

producer/consumer work queues

I'm wrestling with the best way to implement my processing pipeline. My producers feed work to a BlockingQueue. On the consumer side, I poll the queue, wrap what I get in a Runnable task, and submit it to an ExecutorService. while (!isStopping()) { String work = workQueue.poll(1000L, TimeUnit.MILLISECONDS); if (work == null) ...

How to declare array elements volatile in Java?

Is there a way to declare array elements volatile in Java? I.e. volatile int[] a = new int[10]; declares the array reference volatile, but the array elements (e.g. a[1]) are still not volatile. So I'm looking for something like volatile int[] a = new volatile int[10]; but it doesn't work that way. Is it possible at all? ...

Shutting down a TaskExecutor in a web application when the web server is shutdown

I have a web application that makes use of a Spring TaskExecutor. The task executor is started when the web application is loaded for the first time and the thread runs the entire life of the web application. Ever since I added this thread to the application, Oracle Application Server will no longer shutdown gracefully. My guess is that ...

Do I have to synchronize access to encapsulated thread-safe data structures in Java?

Say I have something like this (and I do) class QueBean extends JPanel { private Queue queue = new LinkedBlockingQueue(); public Object poll(){ return queue.poll(); } } with some of these that run on their own threads class ConsumerBean extends JPanel implements Runnable{ private QueBean queBean; public ...

ExecutorService, standard way to avoid to task queue getting too full

Hi, I am using ExecutorService for ease of concurrent multithreaded program. Take following code: while(xxx) ExecutorService exService = Executors.newFixedThreadPool(NUMBER_THREADS); ... Future<..> ... = exService.submit(..); ... } In my case the problem is that submit() is not blocking if all NUMBER_THREADS are occupied. Th...

What are my options for doing multithreaded/concurrent programming in Python?

I'm writing a simple site spider and I've decided to take this opportunity to learn something new in concurrent programming in Python. Instead of using threads and a queue, I decided to try something else, but I don't know what would suit me. I have heard about Stackless, Celery, Twisted, Tornado, and other things. I don't want to have ...

Concurrent Modification Exception thrown by .next from Iterator

Not sure exactly what's wrong here: while(itr.hasNext()) { Stock temp =itr.next(); } This code is throwing a ConcurrentModificationException at itr.next(); Initialization for the iterator is private Iterator<Stock> itr=stockList.iterator(); Any ideas? [The basic code was copied directly from professor's slid...

Concurrency issues

Hi, Here's my situation (SQL Server): I have a web application that utilizes nHibernate for data access, and another 3 desktop applications. All access the same database, and are likely to utilize the same tables at any one time. Now, with the help of NH I'm batching selects in order to load an aggregate with all of its hierarchy - so...

Potential use for SoftReference with value (equals) equality

I previously come to the conclusion that if you need a SoftReference with value (equals) based equality then one had a bad design, excepting an interner from this. This is following Google Collections and Guava not including such a class. But I've come across an issue that I think could use such an object. We have an asset management ...

Binding multiple OnTaskChanged.AfterProperties to one Workflow field.

Hi, I'm creating a State Workflow for WSS and have several tasks that get created throughout it. I wanted to bind all of the OnTaskChanged.AfterProperties to the one Workflow Field so that I can define one rule, to check the status of the task that changed, and re-use that rule wherever I have an OnTaskChanged event. I can't see any pr...

Thread Safety in Javascript?

I have a function called save(), this function gathers up all the inputs on the page, and performs an AJAX call to the server to save the state of the user's work. save() is currently called when a user clicks the save button, or performs some other action which requires us to have the most current state on the server (generate a docume...

Options for storing metadata about CUPS print jobs?

I'm writing a print system that puts a simplified interface on top of CUPS. Users drop jobs into one queue, the system processes them in various ways (statistics, page quotas, etc.), and then offers the user a web interface to dispatch the job to one of multiple printers. Since there may be several user kiosks, an admin station, etc.,...

Python: How to make multiple HTTP POST queries in one moment?

How to make multiple HTTP POST queries in one moment using Python? Using an external library with an example can be a good solution. ...

Elegantly implementing queue length indicators to ExecutorServices

Why, oh why doesn't java.util.concurrent provide a queue length indicators for its ExecutorServices? Recently I found myself doing something like this: ExecutorService queue = Executors.newSingleThreadExecutor(); AtomicInteger queueLength = new AtomicInteger(); ... public void addTaskToQueue(Runnable runnable) { if (queueLength.ge...