好的多线程Java代码的例子?

abh*_*nav 6 java multithreading

我想研究一些好的多线程Java代码.有人可以请一些例子吗?Apache Web服务器是一个很好的选择吗?

谢谢,阿比纳夫.

b_e*_*erb 15

我建议你看一下这本书.它涵盖了几乎所有关于java和并发/多线程的内容,包括编码原理和许多示例.


Old*_*eon 8

我强烈建议你阅读-至少两次- (我在我的第四读数现在)精湛并发的秘密亨氏M. Kabutz博士慷慨地在其网站上公布.

主题包括:

破坏性守门员
的法则分心的守望者
的法则过度沉重的小百货
法则盲目
的法则泄露的备忘录
的法则腐败的政治家
的法律微观管理者
的法律克里特岛
的法律推动突然的法则财富
"不受欢迎的Lutefisk
的法则"施乐复印机的法则

所有这些都是娱乐性和非常丰富的信息.

除了Overstocked Haberdashery之外的其他地方你会找到如下代码:

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();
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

在那里,他不仅采用了CountDownLatch AtomicInteger synchronized(this) 处理的InterruptedExceptionapropriately,他甚至使用了double brace initialiser启动线程!现在如果那不是史诗java是什么?