Examples of good multi-threaded Java code?

I want to learn some good multi-threaded Java code. Can anyone suggest some examples? Is the Apache web server a good choice?

Thanks, Abhinav.

+6
java multithreading
source share
5 answers

I would recommend you take a look at this book . It covers almost everything about Java and concurrency / multithreading, including coding principles and many examples.

+15
source share

I would strongly recommend that you read - at least twice - (I'm reading the 4th reading now) excellent Concurrency Secrets that Dr. Heinz M. Kabutz generously unveiled his website.

Topics include:

Sabotage Doorbell Act
Act of Distracted Spearfisherman
The law of crowded haberdashery
Blind Spot Law
Law of Leakage Memos
Law of a corrupt politician
Micromanager Law
The Law of Cretan Driving
Law of sudden wealth
Uneaten Lutefisk Act
Xerox Law Xerox

All of them are interesting and extremely informative.

Where else, but in Overstocked Haberdashery you will find code like:

public class ThreadCreationTest { public static void main(String[] args) throws InterruptedException { final AtomicInteger threads_created = new AtomicInteger(0); while (true) { final CountDownLatch latch = new CountDownLatch(1); new Thread() { { start(); } public void run() { latch.countDown(); synchronized (this) { System.out.println("threads created: " + threads_created.incrementAndGet()); try { wait(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } } } }; latch.await(); } } } 

where he uses not only CountDownLatch and , but AtomicInteger and synchronized(this) and handles InterruptedException he even uses double brace initialiser to start the stream !! Now, if it's not epic java , what is it?

+8
source share

Best concurreny tutorial in Java ever

Java memory model

+1
source share

Doug Lea A shared double-linked list is a great example of Lock Free coding.

+1
source share

In the concurrency tutorial you will find aspects such as

  • synchronization
  • dead ends
  • as well as basic concepts

are being discussed. If you do not understand how this is used in a real application, check out Jackrabbit

0
source share

All Articles