concurrency

Does a variable accessed by multiple threads in a java servlet need to be declared volatile?

In the book Java Servlet Programming, there's an example servlet on page 54 which searches for primes in a background thread. Each time a client accesses the servlet, the most recently found prime number is returned. The variable which is used to store the most recently found prime is declared as such: long lastprime = 0; Since this...

Native threads in Ruby 1.9.1, whats in it for me?

So, Ruby 1.9.1 is now declared stable. Rails is supposed to work with it and slowly gems are being ported to it. It has native threads.... and a global interpreter lock. Since a GIL is in place, do native threads offer any kind of benefit over green threads in 1.9.1? ...

Deadlock on a single java semaphore?

In one of my recent answers, I gave a theoretical semaphore example of limiting access to memory resources: public static byte[] createArray(int size) throws InterruptedException { semaphore.acquire(size); return new byte[size]; } public static void releaseArray(byte[] array) { semaphore.release(array.length); } I think th...

Is MySQL Connector/JDBC thread safe?

Is the standard MySQL JDBC driver thread-safe? Specifically I want to use a single connection across all threads, but each statement will only be used in a single thread. Are there certain scenarios that are safe and others that aren't? What's your experience here? ...

How to shut down all Executors when quitting an application?

According to Brian Goetz's Java Concurrency in Practice JVM can't exit until all the (nondaemon) threads have terminated, so failing to shut down an Executor could prevent the JVM from exiting. I.e. System.exit(0) doesn't necessarily work as expected if there are Executors around. It would seem necessary to put some kind of public voi...

Concurrent and Blocking Queue in Java

Hello Everybody, I have the classic problem of a thread pushing events to the incoming queue of a second thread. Only this time, I am very interested about performance. What I want to achieve is: I want concurrent access to the queue, the producer pushing, the receiver poping. When the queue is empty, I wand the consumer to block to t...

Optimistic concurrency in ADO.NET Entity Framework

I found an MSDN article that describes how EF handles concurrency when saving changes: By default [...] Object Services saves object changes to the database without checking for concurrency. For properties that might experience a high degree of concurrency, we recommend that the entity property be defined in the conceptua...

How do I optimize for multi-core and multi-CPU computers in Java?

I'm writing a Java program which uses a lot of CPU because of the nature of what it does. However, lots of it can run in parallel. When I run it, it only seems to use one CPU until it needs more then it uses another CPU - is there anything I can do in Java to force different threads to run on different cores/CPUs? ...

The relationship between cores and the number of threads I can spawn

I have a Intel Quad Core CPU. If I was to develop a Winforms application which only be used on my machine (I use C# btw), how many threads can I spawn? Is there some sort of correlation between cores and the max number of threads I can have running at any one time? Would I need to find out how many threads are running at any one time a...

How to run concurrency unit test?

Hi, How to use junit to run concurrency test? Let's say I have a class public class MessageBoard { public synchronized void postMessage(String message) { .... } public void updateMessage(Long id, String message) { .... } } I wan to test multiple access to this postMessage concurrently. Any advice ...

ASP.net Concurrent access session strange behaviour

Hello We have an strange problem with accessing to session variables concurrently. The microsoft documentation says that if two request are made for the same session (using the same sessionId), the second request execute only after the first request has finished. http://msdn.microsoft.com/en-us/library/ms178581.aspx In our cases the be...

Do Applet JSObject javascript calls serialize?

Do applet javascript calls serialize in any proper way? I'm considering implementing a model in which two threads send off javascript commands. One responds to requests from the browser (js), and the other hits the browser periodically. My question is this: what happens if these two javascript requests collide? I'm worried about concurr...

Java parallel work iterator?

I'm looking for a class where I can override a method to do the work, and return the results like an iterator. Something like this: ParallelWorkIterator<Result> itr = new ParallelWorkIterator<Result>(trials,threads) { public Result work() { //do work here for a single trial... return answer; } }; while (itr.hasNext()) { ...

Lock Free Array Element Swapping

In multi-thread environment, in order to have thread safe array element swapping, we will perform synchronized locking. // a is char array. synchronized(a) { char tmp = a[1]; a[1] = a[0]; a[0] = tmp; } Is it possible that we can make use of the following API in the above situation, so that we can have a lock free array ele...

Detecting concurrent usage of software without being online

Hi all I'm looking for a way to detect multiple usages of a piece of desktop software, without them necessarily being online at the time. An online solution could be to log the IP/MAC address and licence key on each start up and detect changes to the IP/MAC address. But if the users of the software are on a local intranet that's not n...

Best ways to handle maximum execution time for threads (in Java)

So, I'm curious. How do you handle setting maximum execution time for threads? When running in a thread pool? I have several techniques but, I'm never quite satisfied with them. So, I figure I'd ask the community how they go about it. ...

Java 5: java.util.concurrent.FutureTask - Semantics of cancel() and done()

I am currently hunting a nasty bug in a multi-threaded environment using FutureTasks and Executors. The basic idea is this to have a fixed number of threads execute individual FutureTasks that compute a result that is to be displayed in a a table (never mind the GUI aspect here). I have been looking at this for so long, I am beginning ...

Can producer-consumer problem be solved without using assignment?

I am interested in finding if producer-consumer problem when there are multiple produce and multiple consumer be solved without using assignment i.e., using functional style of programming? How? Producer-consumer problem Thanks ...

C++ multiple processes?

I've got a project that consists of two processes and I need to pass some data between them in a fast and efficent manner. I'm aware that I could use sockets to do this using TCP, even though both processes will always exist on the same computer, however this does not seem to be a very efficient solution. I see lots of information abou...

.NET or Windows Synchronization Primitives Performance Specifications

Hello *, I am currently writing a scientific article, where I need to be very exact with citation. Can someone point me to either MSDN, MSDN article, some published article source or a book, where I can find performance comparison of Windows or .NET Synchronization primitives. I know that these are in the descending performance order: ...