I want to implement lazy initialization for multithreading in Java.
I have some code of the sort:
class Foo {
private Helper helper = null;
public Helper getHelper() {
if (helper == null) {
Helper h;
synchronized(this) {
h = helper;
if (h == null)
...
It's my understanding that if two threads are reading from the same piece of memory, and no thread is writing to that memory, then the operation is safe. However, I'm not sure what happens if one thread is reading and the other is writing. What would happen? Is the result undefined? Or would the read just be stale? If a stale read is not...
Is there any good and short explanation of how the Actor Model is working compared to threads?
Can't a thread be seen as an actor and send messages to other threads? I see some difference, but it's not that clear for me. Can I use the Actor Model in any language by using threads differently?
...
What i the difference between Clojure STM ( dosync) approach and Java synchronize Block ?
Im reading the code below from "The sleeping barber" problem.
(http://www.bestinclass.dk/index.clj/2009/09/scala-vs-clojure-round-2-concurrency.html)
(defn the-shop [a]
(print "[k] entering shop" a)
(dosync
(if (< (count @queue) ...
Maybe that will sound odd, but I need to schedule priority on oracle connections. It goes like that:
I have one main 'connection' that will pump data out of oracle, and it should be as fast as it can be.
I have two other connections that should (ideally) use all oracle resources not dedicated to the first query.
Is there a way to do ...
I have this class
public class Item
{
public int UniqueKey;
public int Key1;
public int Key2;
public int Key3;
public int Key4;
public string Value;
}
and the collection IEnumerable<Item>
I want to create indexes on items of this collection by Key1, or by Key2, or composite one (Key1 and Key4). The number of ...
I have an app that does an iteration to create points on a graph over time.
While I'm gathering data for each point across the x-axis I also must execute a recursive lookup which effectually means I have a loop inside another loop. This is not scaling too well. I don't see a lot of examples of using a "divide and conquer" solution on it...
I'm working on a simulation project using c++ on both windows and linux.
There will be several thousand objects (Perhaps 3000-5000) in the simulation. In plan to have several threads performing actions on the objects so that it makes good use of multi core machines, for example one thread handling movement and location of the objects, o...
Suppose I was writing an application where users had to book appointments (in my case, a user is paired with an employee and that employee will do work for that user at a particular time of day). How would I ensure that 2 users did not end up booking the same appointment using NHibernate or Entity Framework? Would I open a transaction an...
I want to do the SELECT / INSERT version of an UPSERT. Below is a template of the existing code:
// CREATE TABLE Table (RowID INT NOT NULL IDENTITY(1,1), RowValue VARCHAR(50))
IF NOT EXISTS (SELECT * FROM Table WHERE RowValue = @VALUE)
BEGIN
INSERT Table VALUES (@Value)
SELECT @id = SCOPEIDENTITY()
END
ELSE
SELECT @id = RowID ...
Hello,
First time poster, long time lurker. Figured it's about time I start getting actively involved. So here's a question I've spend all weekend trying to find an answer to.
I'm working on writing a bunch of acceptance tests using Selenium and MbUnit, using the DegreeOfParallelism attribute that MbUnit offers.
My Setup and Teardown ...
I've been trying to find anything that discusses when you should favor the use of monads over actors (in concurrency scenarios), but I've found nothing. In particular, I'm wondering about the use of the Reactive Extensions (LINQ to Events) vs. F#'s MailboxProcessor. Please give examples in addition to any philosophical reasoning you migh...
Objective: to make something like unpretentious map/reduce.
There are many tasks they should be run in parallel, results added to the collection. If the task lasts longer than a certain time (eg 3 seconds) - cancel it.
Which way is faster and more convenient? Share your experiences in building a "correct" multi-threading.
thx in advance....
Hi,
I have changed the timezone of my server per connection basis which is working fine
but most of the addedon Fields in my database tables and timestamp and I am using the CURRENT_TIMESTAMP default value for them to add the inserted date.
Now as I have changed the timezone but this change is not affecting the dateadded fields of m...
We're creating a web service where we're writing files to disk. Sometimes these files will be read at the same time as they are written.
If we do this - writing and reading from the same file - we sometimes end up with files that are of the same length, but where some of the data inside are not the same. So with a 350mb file we get mayb...
Hi all,
I'm interested in whether a select for update query will lock a non-existent row.
e.g.
Table FooBar with two columns, foo and bar, foo has a unique index
Issue query select bar from FooBar where foo = ? for update
If query returns zero rows
Issue query insert into FooBar (foo, bar) values (?, ?)
Now is it possible that t...
I am new to Java and I'm attending a Concurrent Programming course. I am desperately trying to get a minimal working example that can help to demonstrate concepts I have learnt like using 'synchronized' keyword and sharing an object across threads.
Have been searching, but could not get a basic framework. Java programmers, kindly help.
...
Hello,
I am new to ruby on rails and I have just started watching rails casts tutorials.
To parse feeds, I have started using feed zirra.
To fetch multiple feeds at once, feedzirra has this feature
feed_urls = ["http://feeds.feedburner.com/PaulDixExplainsNothing",
"http://feeds.feedburner.com/trottercashion"]
feeds = Feedzirra::Feed....
Possible Duplicate:
Thread safety in Java class
I'm reading Java concurrency in Practice (good book so far), and I've come to an example that puzzles me.
The authors state that this class is not threadsafe
public class MutableInteger{
private int number;
public int getInt(){return number;}
public void setInt(int val...
Why is the pattern considered broken? It looks fine to me? Any ideas?
public static Singleton getInst() {
if (instace == null) createInst();
return instace;
}
private static synchronized createInst() {
if (instace == null) {
instace = new Singleton();
}
}
...