concurrency

How do I synchronize to prevent a java.util.ConcurrentModificationException

Hello I have program consisting of a number of classes. I have a problem with the interraction of two of the classes - WebDataCache and Client. The problem classes are listed below. WebData: This is just a data class representing some data retrieved from the internet. WebService: This is just a web service wrapper class which connects t...

Java mutual exclusion

Hi all, i just have a quick question about concurrent programming in Java. for example, i have a NxN matrix, and there is a corresponding thread for each row of the matrix, if there is no interaction between threads in each row, is it safe (or correct) if multiple threads access and modify separate rows of the matrix simultaneously? Than...

Is this java code thread-safe?

I am planning to use this schema in my application, but I was not sure whether this is safe. To give a little background, a bunch of servers will compute results of sub-tasks that belong to a single task and report them back to the central server. This piece of code is used to register the results, and also check whether all the subtask...

Java: Timer and thread it creates

Hey. I have this question: I have a timer. With scheduleAtFixedRate it creates a new Timer task. In that timer task there is certain code, which may take a while to complete. How can I make sure that Timer won't create new task when the previous one didn't complete yet? Thanks ...

Java: SingleThreadScheduledExecutor & java.util.concurrent.RejectedExecutionException

Hello. I am having this problem, I have private ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor(); and task which is created every 50 millliseconds: executor.scheduleAtFixedRate(myTask, 0, 50, TimeUnit.MILLISECONDS); myTask sometimes take a while to complete (like 2-3 seconds or so), but new...

concurrency in hibernate

I have a servlet that does some work for user and then decrement user's credit. When I watch user's credit in the database in real time, if there are many concurrent requests from the same user, the credit has been deducted incorrectly due to concurrency control. T Assume I have one server and database management used is hibernate. I am...

Update a single object across multiple process in java

A couple of Relational DB tables are managed by a single object cache that resides in a process. When the cache is committed the tables are updated. The DB relational tables are updated by regular SQL queries and not anything more fancier like hibernate. Eventually, other processes got into the business of modifying this object without ...

dedicated thread for io_service::run()

I want to provide a global io_service that is driven by one global thread. Simple enough, I just have the thread body call io_service::run(). However, that doesn't work as run (run_one, poll, poll_one) return if there is no work to do. But, if the thread repeatedly calls run(), it will busy loop when there is nothing to do. I'm looki...

not sure of reason for ConcurrentModificationException

This is my code to construct a possible tour of citys in a Locale l (it's not optimal it's just to give my AI search a head start). I'm getting a ConcurrentModificationException, which to my knowledge happens when more than one piece of code accesses an variable / collection and attempts to modify it. Causing this code to get unhappy: ...

Is there a tool to model/simulate software concurrency?

Is there a good tool out there that can model an application concurrency/locking scheme in a graphical way and that can simulate some of the aspects? I know that Petri nets can be used for that more or less, but I don't know a good GUI tool that can design and simulate. Is UML in any way usable for such purposes? Any good links are ...

.NET - Dictionary locking vs. ConcurrentDictionary

Hello, I couldn't find enough information on ConcurrentDictionary types, so I thought I'd ask about it here. Currently, I use a Dictionary to hold all users that is accessed constantly by multiple threads (from a thread pool, so no exact amount of threads), and it has synchronized access. I recently found out that there was a set of t...

What Use are Threads Outside of Parallel Problems on MultiCore Systesm?

Threads make the design, implementation and debugging of a program significantly more difficult. Yet many people seem to think that every task in a program that can be threaded should be threaded, even on a single core system. I can understand threading something like an MPEG2 decoder that's going to run on a multicore cpu ( which I've...

Are semaphores "complete"?

Can every imaginable synchronization problem be solved with judicious use of semaphores? What about weak semaphores? ...

Why runtime error occurs when 10 user concurrent request the same page?

This page I use crystal report to generate a report, but if 10 user or more request this page at the same time, some of the user will get a runtime error. But if normal use, everything is all right. Sample code: report.Load(Request.PhysicalApplicationPath + "reports\\test.rpt"); report.FileName = Request.Ph...

Under what conditions will BlockingQueue.take throw interrupted exception?

Let us suppose that I have a thread that consumes items produced by another thread. Its run method is as follows, with inQueue being a BlockingQueue boolean shutdown = false; while (!shutdown) { try { WorkItem w = inQueue.take(); w.consume(); } catch (InterruptedException e) { shutdown = true; } } ...

Thread safety in JSF

Assume that we have Spring bean UserController with singleton scope. All my further reasoning is based on my assumption that "singleton" scope is almost similar to application scope i.e. we have only one instance for all users. If this is wrong assumption then tell me about it, please. So, we have a web-form with several fields. Two ...

Limiting concurrent threads equal to number of processors?

Are there any benefits to limiting the number of concurrent threads doing a given task to equal the number of processors on the host system? Or better to simply trust libraries such as .NET's ThreadPool to do the right thing ... even if there are 25 different concurrent threads happening at any one given moment? ...

Java: Concurrency for a game

I'm writing a simulation of Bananagrams for fun. I want to use concurrency but I'm not entirely sure how. I have a main method in a Game class. Each of the player threads works towards a solution. At certain points, a player will "peel". During this operation, every player is dealt a new tile. One of the player threads must notify the G...

Cleaning a buffer before termination

I'm writing a program similar to the producer-consumer problem. Here's my main code: public class PipeProcessor { private volatile boolean close = false; Pipe pipe; Output out; public PipeProcessor(Pipe pipe) { this.pipe = pipe; } public void run() { while(!close) { out.output(pipe.get()); } while(pipe.size() > 0) out.outp...

Concurrency for compound edits

I have these classes that I use to create objects that I want to store at runtime Class Person String name Pet[] pets Class Pet String name Person[] owners boolean neutered At first I used these HashMaps to store them HashMap people HashMap pets But I wanted to make the implementation concurrent so I changed th...