Discussions

News: A short example of a Swing Thread Deadlock

  1. A short example of a Swing Thread Deadlock (14 messages)

    The Swing classes have several locks that are acquired in different orders, depending on what order the GUI methods are called.

    This poses a well-known problem, in that we need to use SwingUtilities.invokeLater(Runnable) to access the gui, else we may get a deadlock. In the latest The Java Specialists' Newsletter, Heinz demonstrates a small piece of code that causes the GUI to hang up.

    On another note, The Java Specialists' Newsletters celebrated their 4th anniversary with their 100th edition, entitled "Java Programmers aren't born" at the end of November 2004.

    Threaded Messages (14)

  2. +1 on Programmer's aren't born[ Go to top ]

    I'm totally bias, but I have to say the second link is dead on. Programmers are not born. It requires a certain personality and drive to become good. Very few people become elete programmers and even then it doesn't last very long. Even someone as great a Woz reached his peak and then changed focus. Though I think it's harder to fake "professional soccer" than programming. The analogy in the newsletter still works, just noting a difference.
  3. -1 on Programmer's aren't born[ Go to top ]

    I agree with parts of the second message, but the guy, to me, is overdoing it!

    "I believe that being a programmer is not a job, it is a life. In order to learn it, you need to eat, breathe, sleep Java... If we take into account a few responsibilities, you have an additional 1.5 hours in the morning, and 6 hours in the evening.... I am not making this up."

    This is way over the top. What he seems to suggest is that you have work, a few responsibilities, and the rest of your time is dedicated to... Java!?!? I love my job, don't get me wrong, but, I love my life, too!

    What he is saying worked for me for a period of time (at the university, for example). I remember having this burn inside my stomach while away from programming/unresolved bugs etc. It still happens, but there are more "business as usual" days now.

    (Zipped version of this post for casual readers of TSS: "Dude, get a life!")

    Goran.

    P.S. This post is NOT to say that programmers ARE born. (Title seems to suggest that :-))
  4. 0 on Programmer's aren't born[ Go to top ]

    My opinion is somewhat in the middle. On one end I agree; to be a good programmer you need to have bits flowing in your blood, you have to have that sixth sense that tells you that this totally illogical behaviour is most probably caused by the six inverter bit not being inverted (you catch my drift).

    On the other hand, I know of this totally briljant software engineer (female, BTW, no pun intended), university degree with honors, started working at a bank but was totally unable to function within an organisation. Unable to communicate and cooperate.

    So as always everything is a balance. But the last two decades has shown often enough that it is too easy to fake IT skills, especially when the demand is high.
  5. 0 on Programmer's aren't born[ Go to top ]

    Well, I think a Bachelor, a Master or even a Phd degree don't certify you are a good programmer. And I think programmers, engineers, writers, musicians, mathematicians etc. are born and aren't born.

    There are people with less difficulties than other. Someones like Gauss, Mozart and Goethe are few examples of "born" people. But it don't means that a "normal" person cannot be a brilhant programmer. Remember Thomas Edision: 1% inspiration, 99% transpiration.

    The author referenced the Bell Curve. I think that is a bad reference...

    Here's the why: http://www.ucm.es/info/Psyap/iaap/rocio1.htm

    Thanks for the patience
    Rafael
  6. don't we all get carried away?[ Go to top ]

    I still think it makes valid points, even if some parts aren't necessarily true or good examples. If Mozart never played an instrument because he lived in he amazon or Wayne Greztsky never picked up a hockey stick, any innate talent/potential probably would have gone unnoticed. I call it luck. The right job meeting the right person at the right time to produce someone that excels.
  7. -1 on Programmer's aren't born[ Go to top ]

    Instead of christmas presents, buy books from Amazon.com on >Java, Object orientation, Design Patterns, etc

    What, no iPOD ? !!. I dont agree with all of this. You dont need to know all of Java to be useful. You just need to know enough to do the job at hand. No need piling up knowledge you'll never use. The wise programmer is the one that learns as he goes and understands that the world does not revolve around Java or any technology in particular (heck a new one soon pops up anyway). Programming languages are similar enough that they can be picked up easily. Whats so new about Web services ? Whats the big deal with AOP, SOA and all that hype. I'll learn them when my job demands it man. An inability to adapt to new language suggests a deficiency of fundamental software engineering knowledge.

    There is more to life than reading Java books what of the Bible, how can a man neglect his own soul for a subject as transient as Java.

    So my advice, when U wake, read your Bible and pray, after work read the newspaper etc (for example read the economist, businessweek, Men's Health mags etc) , chill out and watch TV or just chill with the ones you love. Try and learn about other stuff that does not relate to computers.

    ps
    Heinz, I do love your newletters keep them coming. But please get a balance.
  8. deadlock[ Go to top ]

    it's a simple deadlock beetween the lock
    that protect class initializer and the
    AWTTreeLock.

    it's not a swing bug !
  9. Second newsletter[ Go to top ]

    Heinz sent a second newsletter after the first one with the deadlock, where he stated, that it's just a problem with the static initializer, not with SWING.
    Well, it was a little mistake in the first newsletter, but that can happen...

    Here is his class which shows the typical deadlock problem with static initializers:


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

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

      private StrangeProblem() {
         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) {
      }
    }
  10. Second newsletter[ Go to top ]

    There are somethings that you should just not do. This is an example.
  11. Please, why are you abusing the static initializer like that?

    main is for starting up whatever needs starting, NOT the static initializer. That is just wrong and anyone writing this code gets what they deserve. Swing cannot keep you from writing shit code.
  12. I Can Cause an OutOfMemoryError[ Go to top ]

    void iAmAnIdiot() {
       while(true) {
          iAmAnIdiot();
       }
    }

    This occurs in all programming languages in one form or another.

    I better switch to management ;-)
  13. This is a pretty interesting article. I recently read
    this article, which contains code for a DeadlockDetectingLock which the authors have written (which subclasses the JDK 5.0 ReentrantLock implementation), and contains some simple deadlock (i.e. circular locking) detection. I wonder if this would be possible to detect using AOP and standard synchronized blocks in current JVMs? i.e. could we use something like ASM to intercept calls to monitorenter/monitorexit, and then recursively walk the thread tree before acquiring , searching for circular references? I havent looked into this in detail, but this could be pretty useful.
  14. Brilliant Programmers are born[ Go to top ]

    I originally believe anyone could become a brilliant programmer given time. After much trial and effort, I can admit I was sadly wrong. Some have it, some don't. It doesnt make them "lesser beings" or anything, its just that programming is just not what they were destined to become.


    Remember Thomas Edision: 1% inspiration, 99% transpiration.


    Thomas Edison was a hack who stole the inventions of Nikola Tesla and claimed them as his own. Tesla was a born master of all things electric. Edison was just better at PR.
  15. Programmers aren't born[ Go to top ]

    I received very few "neutral" responses to my newsletter 100.

    The most important message I was trying to bring across is this:

    Do not become a programmer just for the money

    And this is a message for those who are thinking of becoming programmers, not for those who already are successful. It is a lot of hard work, with very little pay.

    Heinz