JDK 5.0: More Flexible, Scalable Locking 50
An anonymous reader writes "Multithreading and concurrency are nothing new, but one of the innovations of the Java language design was that it was the first mainstream programming language to incorporate a cross-platform threading model and formal memory model directly into the language specification. While this simplifies the development of platform-independent concurrent classes, it by no means makes writing concurrent classes trivial -- just easier."
java first? (Score:1)
dont know about first mainstream, but when it comes to a cross-platform threading model, i think ADA was first
Re:java first? (Score:3, Insightful)
Re:java first? (Score:5, Interesting)
Multi-threading is only hard because most languages have piss-poor support for multi-threading. I recommend to anyone that they go away and learn about Ada tasks and the select statement to see how it ought to be done.
Erlang (Score:4, Interesting)
Re:Erlang (Score:2)
I don't consider Erlang a mainstream language: its userbase is quite small..
Does Ada qualify as mainstream?
IMHO yes, but YMMV.
Re:java first? (Score:1)
Re:java first? (Score:1)
Enjoy!
Re:java first? (Score:1)
Enjoy!
WTF? (Score:4, Funny)
So called "improved" locking (Score:2, Interesting)
JSR-166 is not a total loss as the lock-free stuff is more significant.
BTW, I came up with an improved fut
Doug Lea's concurrent Java (Score:5, Informative)
The util.concurrent package has been very popular among open-source projects, and is known for its strong performance. In many cases, migrating from util.concurrent should be as simple as importing java.util.concurrent.class instead of EDU.oswego.cs.dl.util.concurrent.class .
Of course, one of the improvements made by JSR166 is to genericize all the interfaces and classes, so what uses to be a BlockingQueue is now a type-safe, parameterizable class BlockingQueue<E>.
Not all of the toolkit made it into the 5.0 release in time, and the missing stuff, referred to as jsr166x [oswego.edu], which comprises "concurrent sorted maps and sets, as well as concurrent double-ended queues (deques)", is available for use.
Doug also offers a JSR166 maintenance update [oswego.edu] that fixed a bug in one of the classes.
can I use it with classPath ? (Score:2)
so frankly whats the point
I want an open JVM and that means open Libs if I am going to bugfix and then take my ball and play elsewhere
yes there is parrot but think a good set of libs like the CLR for parrot would be good...
but I want to use java maybe now...
regards
John Jones
Re:Doug Lea's concurrent Java (Score:1)
Re:Bah (Score:3, Informative)
Hasn't done one original thing? Well, a cross platform skinnable lightweight UI package that sits on top of a JIT bytecode compiler, that gives you binary compatibility between MFC, GTK, qt and other libraries.... that is pretty cool.
Alsom the JCP is pretty revolutionary in software development, and a very good start for originality.
Linux community never really adopted Java, it is a shame, it isn't
Re:Bah (Score:2)
From the story submission: Have fun in C++ land though!
The fact you think the only possible alternative I could mean is C++ discredits you.
Re:Bah (Score:2)
Wait....qt? Did you just miswrite that, or did an swt implementation with qt support, official or unofficial, finally make it out somewhere in the wild?
Re:Bah (Score:2)
Aaaah motif and gtk. Why not a qt impl? Code so drastically different?
Parent voted for Bush (Score:1, Offtopic)
Those who voted Bush gave thier first and only affirmative acceptance and vote of persnal merit to the actions undertaken in Iraq. Prior to this no American had given a personal vote of acceptance to the actions undertaken, if you voted Bush, then you approve of Fallujah, of the troops for oil programs, and the rest.
You voted into power the wealthies
Re:Parent voted for Bush (Score:2)
Bush himself said before the vote that it wasn't a vote to go to war. Of course he's proven on many occasions that lying is not a problem for him.
Re:Parent voted for Bush (Score:1)
Not one.
Re:Parent voted for Bush (Score:2)
Re:Dumbass doesn't know what he is talking about (Score:2)
"In a major victory for the White House, the Senate early Friday voted 77-23 to authorize President Bush to attack Iraq if Saddam Hussein refuses to give up weapons of mass destruction as required by U.N. resolutions."
The CNN story doesn't provide the actual text of the bill and I'm too lazy to look it up.
It seems to me that in order to determine if there were weapons of mass destruction, you'd have to finish the inspections and that would be an implicit (if not explic
Re:Jesus Christ man, take off the blinders (Score:2)
And he didn't have any WMDs.
"Do you have any other way you can twist this to fit your backward logic and failed ideology?"
I didn't express any ideology failed or otherwise. As far as backward logic is concerned, it's you who insists that Bush met the terms of the bill since Saddam wouldn't give up the imaginary WMDs.
I'll let you have the last word.
Pthreads does *not* include a formal memory model (Score:1)
And pthreads aren't quite pervasive enough to count as "might as well be part of the language" -- I've worked on many C implementations that did not have pthreads capabilities, even though a good fraction of them did have some kind of threading.
Before telling people they're ignorant, it's good to be sure of your own information.
For example, I'm tempted to say that the POSIX committee is being disbanded, but I don't have official confirmation of that so
Re:Bah (Score:2)
You mean apart from win32, right? ... that's only what, a couple of hundred million hosts.
Maybe python lets you do useful cross platform threading ... but I didn't think so, and I'm not sure I'd classify it mainstream anyway (certainly not to the extent that Java is -- and personaly I think python is a better lanugage, but it isn't as mainstream).
Then again I think the entire argument is bogus, it's like advocating for GCC because
Re:Bah (Score:2)
POSIX threads; not only cross-platform and essentially built into C
Thats a C library. And not a language feature.
HUGHE difference. The compiler dosn't know anything about pthreads
angel'o'sphere
Re:Bah (Score:2)
What does first matter? Java does everything THE BEST so being first really means nothing.
Laguage or Library (Score:1)
We've had threading in libraries for years (e.g. DCE, Posix, and NT threads). In fact, doesn't Java itself use those libraries to provide its own cross platform thread abstraction? In that sense, Java is nothing special in that ther
.. and formal memory model (Score:3, Informative)
Re:Laguage or Library (Score:1)
Different processors have different memory semantics (differing degrees of cache coherency, for example), and most threading libraries simply "inherit" the memory semantics of the underlying processor architecture, so concurrent code may well behave differently on one processor that it will on another. This is why a formal, cross-platform memory model is required to achieve t
Re:Laguage or Library (Score:2)
This sounds like a lot of nonsence to me. C libs like pthreads run on top of an OS which runs on top of the processor. In what way are differences in cache coherency among processors exposed by the OS an
It's the memory model.. (Score:2)
It's the memory model.. =)
It defines how information can be cached for a thread, when this information has to be written back into main memory, which kind of operations are atomic. etc.
It's not just about memory allocation and disposal but access to that
So why doesn't synchronized map to ReentrantLock? (Score:3, Interesting)
The dilemma about when to use ReentrantLock would go away. For simple situations and beginning programmers, just use synchronized, confident in the knowledge that where A Better Way is available, your code will get it, but it will still work fine on earlier JVMs (assuming synchronized ever worked on them).
The extra features of ReentrantLock are there when needed, and it's only when you use them that your code is Java 5 specific.
Why wasn't it done this way?
Re:So why doesn't synchronized map to ReentrantLoc (Score:2)
Given ReentrantLock has the same semantics as synchronized, performs better and has some extra features, why hasn't synchronized been redefined to use ReentrantLock? It would become compiler magic to, in effect, automatically generate a try-finally with a call to unlock() in the finally.
Because that compiler magic would move towards real magic in case you have programmer defined try/finally blocks allready.
Suppose you have a exception comming from way down under library calls
Re:So why doesn't synchronized map to ReentrantLoc (Score:1)
But synchronized has the same issue - there may be times that releasing the lock doesn't work and throws an exception. The JVM spec says the underlying monitorexit bytecode instruction can throw NullPointerException or IllegalMonitorStateException. Both of these are runtime exceptions that would most likely stop the whole application, and would certainly hide any exception that had occurred in the code within the block. As you might expect, the unlock() method of ReentrantLock can throw
Re:So why doesn't synchronized map to ReentrantLoc (Score:1)
There are more complicated reasons, but I think its safe to say that there are a lot of people at Sun who have already thought of this, and that there will be scalability improvements in synchronization in future JVM versions.
Article Failings and Synchronized vs Locks (Score:1)
I have a few issues with this article. Why isn't there any mention of exactly which JVM he is using? Why is there no source code for his tests?
I happen to write a JVM for a living, and there are huge differences between how locks perform in different situations on the different VMs.
When it comes to using synchronized vs Locks, and that synchronized should be implemented with the methods in Lock et.c. people tend to miss two important facts.
Re:Article Failings and Synchronized vs Locks (Score:1)
Why no source code? Well, I have no objection to posting it, but I thought it would detract from the point. This is an article for beginners, who want to know when and how to use these new language features and what it buys them.
You are correct that the actual numbers are going to be sensitive to the distribution of other work done in the inner loop other than locking. The goal of