Home Javatutorials Causing Deadlocks in Swing Code,java newsletter,java,tutorial



Causing Deadlocks in Swing Code,java newsletter,java,tutorial
Posted on: April 18, 2011 at 12:00 AM
This page discusses - Causing Deadlocks in Swing Code,java newsletter,java,tutorial

Causing Deadlocks in Swing Code (Follow-up)

2005-01-19 The Java Specialists' Newsletter [Issue 101b] - Causing Deadlocks in Swing Code (Follow-up)

Author: Dr. Heinz M. Kabutz

JDK version: Sun JDK 1.5.0_01

If you are reading this, and have not subscribed, please consider doing it now by going to our subscribe page. You can subscribe either via email or RSS.

It is very dangerous sending out code samples that one does not understand fully. So it was with the last newsletter. Fortunately Aleksey Gureev pointed out to me that the main problem was not with the Swing event thread, but rather with calling a static method from another thread before the static initializer block has completed. For example, the following code displays the same problem:

public class StrangeProblem2  {
  static {
    new StrangeProblem2();
  }

  private static void staticMethod() {
    System.out.println("This is never reached");
  }

  private StrangeProblem2() {
     Thread t = new Thread() {
      public void run() {
        System.out.println("We will now call the static method...");
        staticMethod();
        System.out.println("Static method was called.");
      }
    };
    t.start();

    try {
      t.join();
    } catch (InterruptedException e) {
      e.printStackTrace();
    }
  }

  public static void main(String[] args) {
  }
}
  

Kind regards

Heinz

This material from The Java(tm) Specialists' Newsletter by Maximum Solutions (South Africa). Please contact Maximum Solutions for more information.

Related Tags for Causing Deadlocks in Swing Code,java newsletter,java,tutorial:


More Tutorials from this section

Ask Questions?    Discuss: Causing Deadlocks in Swing Code,java newsletter,java,tutorial  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.