Look into the new Java concurrency facilities (in the java.util. Concurrent package ) which have been added in Java 5. It provides functionality that is more high-level than regular Thread s which will make it easier (and less error-prone) to write concurrent applications.
The Lesson: Concurrency of The Java Tutorials would be a good place to start.
Look into the new Java concurrency facilities (in the java.util. Concurrent package) which have been added in Java 5. It provides functionality that is more high-level than regular Threads which will make it easier (and less error-prone) to write concurrent applications.
The Lesson: Concurrency of The Java Tutorials would be a good place to start. So far, I've only used the ExecutorService, which allows can produce thread pools, to which new tasks can be handed off in units of Runnables or Callables (which can return values after execution as Futures), and the actual threading code is handled by the ExecutorService. For example, performing some calculation using a thread pool of 2 threads, and getting the result can be as simple as: ExecutorService es = Executors.
NewFixedThreadPool(2); Future f1 = es. Submit(new Callable() { public Integer call() { // Do some processing... return someInteger; } }); Future f2 = es. Submit(new Callable() { public Integer call() { // Do some processing... return someInteger; } }); Integer firstInteger = f1.get(); Integer secondInteger = f2.get(); In the above (untested) code, all I have to worry about is making a couple of Callables and submiting it to the ExecutorService and later on, using the Futures to retrieve the result.
The catch is, once the get method of the Future is called, if the processing isn't complete, the program will stop until the result of the Future can be retrieved. So, in this example, even if the result of f2 is available before f1, the program will wait until the result of f1 is available. In terms of reading material, on my list of books to purchase soon is Java Concurrency in Practice by Brian Goetz, which comes up often when concurrency in Java is brought up.
The Concurrency Utilities page from the Java 5 documentation has more information as well.
The best tip has got to be: get your synchronization correct! This may seem somewhat obvious but an understanding of the Java Memory Model is vital, particularly how volatile and final fields work, how synchronized acts as both a mutex and a memory barrier and then the new java.util. Concurrent constructs as well.
Always a good tip - if most of your classes are immutable everything becomes so much easier as immutability removes the need to worry about locks from many to few places of concern.
1. I always design classes to be immutable and only make mutable if its needed. – Fortyrunner Mar 2 '09 at 8:19.
Check out the forthcoming fork-join framework. The fork-join framework enables developers to achieve fine-grained parallelism on multicore architectures. Also you may want to check out JVM based languages like Clojure that claim to make multicore parallel programming easier.
As an alternative to Java's own shared-memory approach to concurrency you could also look into Actor-based concurrency using Scala on top of Java, which provides an easier model for concurrent programming.
You can try to use a parallelism patterns library such as Skandium for Java. Simply choose the parallelism pattern you want and fill in the missing hooks. Some of the patterns sopported in Skandium are: Master-slave: Farm(nested); Pipeline: `Pipe(stage1, stage2); For iteration: For(nested, i); Conditional iteration: While(nested, condition); Conditional branching: If(condition, trueCase, falseCase); Map-reduce: Map(split, nested, merge); Map-reduce with different code paths: Fork(split, nested, merge); Recursive divide and conquer: DaC(condition, split, nested, merge); All patterns can be nested and combine, so you can have farm inside of a divide and conquer, etc.
The best book with practical tips has been Java Concurrency in Practise. It is a must read for all java programmers, even those who thinks they don't do any concurrent programming, because java has many hidden threading in its various libraries (swing comes to mind, same with servlets).
My tip: Understand the Java Memory Model (since JDK 5 and higher). Most people do not know, that synchronization, volatile, and final have an additional meaning beyond the normal multi-threading scope. Java is fine for multi-cpu and multi-cores.
If you program it right and you invest some brain, you get a highly concurrent server system to utilize 8-cores including a lot of synchronization and so on. We are quite happy with it... JDK6 is better than JDK5 and everything below sucks on multi-cpu machines.
Check out Brian Goetz's talk From concurrent to Parallel from Devoxx 2008. Not many tips there, but it gives you an idea where Java concurrency is heading to.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.