concurrency

Is there any way or tool that I can use to verify whether my API is thread safe in Java?

Hi I make a tool and provide an API for external world, but I am not sure whether it is thread safe. Because users may want t use it in multiple-thread environment. Is there any way or tool that I can use to verify whether my API is thread safe in Java? ...

Why j.u.c.CopyOnWriteArrayList creates local lock variable inside methods.

I was recently checking implementation of the j.u.c.CopyOnWriteArrayList in OpenJDK's sources and found that the lock variable defined inside the class, is redeclared with following statement final ReentrantLock lock = this.lock; inside all the methods which requires this variable. Any specific reason for doing such redeclaration of t...

DataTable Concurrency Locking

I'm helping spruce up an application, and it's full of concurrency issues. I'm attempting to work through them, and came across a section that's using DataTables. The datatable itself is static, shared across many threads. I know that using dt.Select("...") itself needs a lock statement, or you'll have issues when adding/removing rows ...

pfsockopen thread-safe?

I'm writing a PHP site which connects to a Java server to get data. It does this via a socket. To improve performance I'd like to use pfsockopen() to connect to the server, so a new connection (with costly handshake) doesn't have to be opened for every request. What I can't find in the documentation though, is this thread safe? If PHP i...

Java: Example for unsafe publication

Possible Duplicate: Java multi-threading & Safe Publication I did not understand what unsafe publication is. Can anyone provide a simple example for unsafe publication and explain the adverse effect based on the example. EDIT: This is not a duplicate of the question mentioned as "Possible duplicate". Please reopen this. ...

How to accelerate reads from batches of files

I read many files from my system. I want to read them faster, maybe like this: results=[] for file in open("filenames.txt").readlines(): results.append(open(file,"r").read()) I don't want to use threading. Any advice is appreciated. the reason why i don't want to use threads is because it will make my code unreadable,i want to fi...

SwingWorker doesn't work as expected

I'm trying to find the differences between SwingWorker execute() vs doInBackground().So I have written this simple program to test the difference. public static void main(String[] args) { // TODO code application logic here for(int i=0;i<10;i++){ try { new Worker().execute(); } catch (Exception ex) {...

Static method Issue in C#.net application

I'm using a static method in a class, this static method contains a connection string. I use this static method in all other methods to open a database connection and I dispose the connection within this method. After I deploy this application in IIS, when two users login to the application on two different machines and access the same ...

Lock-free queue algorithm, repeated reads for consistency

I'm studying the lock-free (en-,de-)queue algorithms of Michael and Scott. The problem is I can't explain/understand (nor the paper does, apart from the comments in the code itself) a couple of lines. Enqueue: enqueue(Q: pointer to queue_t, value: data type) E1: node = new_node() // Allocate a new node from the free list ...

In Brian Goetz Concurrency In Practice, why is there a while(true) in the final example of a scalable cache?

In code listing 5.19 of the Brian Goetz book Concurrency In Practice, he presents his finished thread safe Memoizer class. I thought I understood the code in this example, except that I don't understand what the while ( true ) is for at the start of the public V compute(final A arg) throws InterruptedException method. Why doe...

Multithreading in MySQL?

Are MySQL operations multithreaded? Specifically, on running a select, does the select (or join) algorithm spawn multiple threads to run together? Would being multi-threaded prevent being able to support a lot of concurrent users? ...

What are the possible ways to do garbage collection in concurrent systems?

I need to write a garbage collector for an interpreter that will support concurrency, but I can only find information about garbage collection without anything to do with concurrency. Are there specific methods for garbage collection of objects in multithreaded systems? Where can I find information on their architecture and implementati...

Access guarantees of ML Refs?

Are there any access guarantees with ML's Ref type in the face of concurrent access? ...

How does a synchronized statement work in this case?

Assume I have a class like this: public class Server { public static void main(String[] args) { Map<Integer, ServerThread> registry = Collections.synchronizedMap(new LinkedHashMap<Integer, ServerThread>()); ... while(true) { Socket socket = serverSocket.accept(); ServerThread serverThread = new...

Displaying JWindow in the event dispatching thread

What I am trying to do is have a small splash screen appear while my program is loading something. This is what I have: SplashScreen.showSplashScreen(); // Do stuff that takes time. SplashScreen.hideSplashScreen(); All the showSplashScreen() method does is create a new JWindow in the middle of the screen and make it visible. Now this...

Thread safety in java

All, I started learning Java threads in the past few days and have only read about scenarios where even after using synchronizer methods/blocks, the code/class remains vulnerable to concurrency issues. Can anyone please provide a scenario where synchronized blocks/methods fail ? And, what should be the alternative in these cases to ensu...

Linq to SQL Data Concurrency - Is it safe to use only PKs?

I am getting an error in my MVC-based website surrounding data concurrency in Linq to SQL: "Row Not Found Or Changed" After reading several posts on here it seems as though an accepted solution is to set all non-Primary key fields to UpdateCheck = false in the dbml designer. Before taking the plunge with this, I wanted to ask, will I ...

Indexing Lucene with Parallel Extensions (TPL)

I'd like to speed-up the indexing of 10GB of data into a Lucene index. Would TPL be a good way to do this? Would I need to divided the data up into chunks and then have each thread start indexing chunks? To keep the UI responsive would BackgroundWorker be the best approach, or Task, or something else? Does SOLR already do something l...

ScheduledThreadPoolExecutor + setXXXXShutdownPolicy()

There are two properties with the following getters (and accompanying setters) in ScheduledThreadPoolExecutor: boolean getContinueExistingPeriodicTasksAfterShutdownPolicy() Get the policy on whether to continue executing existing periodic tasks even when this executor has been shutdown. In this case, these tasks will only termina...

Can a C# blocking FIFO queue leak messages? What's wrong in my code?

Hello, I'm working on an academic open source project and now I need to create a fast blocking FIFO queue in C#. My first implementation simply wrapped a synchronized queue (w/dynamic expansion) within a reader's semaphore, then I decided to re-implement in the following (theorically faster) way public class FastFifoQueue<T> { priva...