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.
-
A short example of a Swing Thread Deadlock (14 messages)
- Posted by: Heinz Kabutz
- Posted on: January 18 2005 17:45 EST
Threaded Messages (14)
- +1 on Programmer's aren't born by peter lin on January 20 2005 11:16 EST
- -1 on Programmer's aren't born by Goran Pusic on January 21 2005 03:54 EST
-
0 on Programmer's aren't born by Tom Eugelink on January 21 2005 04:19 EST
- 0 on Programmer's aren't born by Rafael Forte on January 21 2005 06:30 EST
- don't we all get carried away? by peter lin on January 21 2005 08:39 EST
- -1 on Programmer's aren't born by Tochi Tochi on January 22 2005 01:17 EST
-
0 on Programmer's aren't born by Tom Eugelink on January 21 2005 04:19 EST
- -1 on Programmer's aren't born by Goran Pusic on January 21 2005 03:54 EST
- deadlock by Remi Forax on January 20 2005 11:44 EST
- Second newsletter by Thomas Eichberger on January 20 2005 12:15 EST
- Second newsletter by Cory Wandling on January 20 2005 15:41 EST
- Static Initializer Abuse Hotline needed by Dave C on January 21 2005 14:29 EST
- I Can Cause an OutOfMemoryError by Jon Kofal on January 21 2005 03:52 EST
- A short example of a Swing Thread Deadlock by rory Winston on January 21 2005 09:56 EST
- Brilliant Programmers are born by Stan Brown on January 21 2005 10:24 EST
- Programmers aren't born by Heinz Kabutz on January 23 2005 06:08 EST
-
+1 on Programmer's aren't born[ Go to top ]
- Posted by: peter lin
- Posted on: January 20 2005 11:16 EST
- in response to Heinz Kabutz
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. -
-1 on Programmer's aren't born[ Go to top ]
- Posted by: Goran Pusic
- Posted on: January 21 2005 03:54 EST
- in response to peter lin
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 :-)) -
0 on Programmer's aren't born[ Go to top ]
- Posted by: Tom Eugelink
- Posted on: January 21 2005 04:19 EST
- in response to Goran Pusic
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. -
0 on Programmer's aren't born[ Go to top ]
- Posted by: Rafael Forte
- Posted on: January 21 2005 06:30 EST
- in response to Tom Eugelink
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 -
don't we all get carried away?[ Go to top ]
- Posted by: peter lin
- Posted on: January 21 2005 08:39 EST
- in response to Goran Pusic
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. -
-1 on Programmer's aren't born[ Go to top ]
- Posted by: Tochi Tochi
- Posted on: January 22 2005 13:17 EST
- in response to Goran Pusic
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. -
deadlock[ Go to top ]
- Posted by: Remi Forax
- Posted on: January 20 2005 11:44 EST
- in response to Heinz Kabutz
it's a simple deadlock beetween the lock
that protect class initializer and the
AWTTreeLock.
it's not a swing bug ! -
Second newsletter[ Go to top ]
- Posted by: Thomas Eichberger
- Posted on: January 20 2005 12:15 EST
- in response to Heinz Kabutz
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) {
}
} -
Second newsletter[ Go to top ]
- Posted by: Cory Wandling
- Posted on: January 20 2005 15:41 EST
- in response to Thomas Eichberger
There are somethings that you should just not do. This is an example. -
Static Initializer Abuse Hotline needed[ Go to top ]
- Posted by: Dave C
- Posted on: January 21 2005 14:29 EST
- in response to Thomas Eichberger
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. -
I Can Cause an OutOfMemoryError[ Go to top ]
- Posted by: Jon Kofal
- Posted on: January 21 2005 15:52 EST
- in response to Dave C
void iAmAnIdiot() {
while(true) {
iAmAnIdiot();
}
}
This occurs in all programming languages in one form or another.
I better switch to management ;-) -
A short example of a Swing Thread Deadlock[ Go to top ]
- Posted by: rory Winston
- Posted on: January 21 2005 09:56 EST
- in response to Heinz Kabutz
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. -
Brilliant Programmers are born[ Go to top ]
- Posted by: Stan Brown
- Posted on: January 21 2005 10:24 EST
- in response to Heinz Kabutz
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. -
Programmers aren't born[ Go to top ]
- Posted by: Heinz Kabutz
- Posted on: January 23 2005 06:08 EST
- in response to Heinz Kabutz
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