So I just learned that Java's GUI-framework "Swing" is not thread-safe (and neither is Microsoft's "Windows Forms"). What that means is that GUI components may only be manipulated by a single thread. If you ignore this fact (or simply assume that the framework has to be thread-safe when in reality it is not), you better be prepared for some really weird errors (aka race conditions) or in the case of WinForms, exceptions.
There are several justifications for that, one of which is performance (locking is expensive, whether you're using multiple threads or not) and the other is pragmatism (most GUI applications are single-threaded). This is all good, but we're in a multi-core world now and unless you want your applications to become slower in the future, you'll eventually have to go multi-threaded as well.
The problem is that once you go multi-threaded, you'll have to make sure yourself, that you synchronize access to the GUI-components. This is something to get wrong very easily and since most programmers aren't concurrency experts, I'm sure that the number of concurrency-related bugs in GUI-applications will go up dramatically in the future. That's why I'm inclined to think that it would have been better to make these frameworks thread-safe from the start, because unlike most GUI-programmers, the library writers at Sun and Microsoft tend to know what they're doing (no offense).
Kai.Jaeger.Blog
-
About me
This is the personal weblog of Kai Jäger, a twentysomething technical project manager from Germany. -
Ajax in der Praxis
My book on Ajax. Available online and from your local bookstore - provided that you live in Germany.
-
Tags
-
Articles
- JavaScript for people who are in slightly less of a hurry - part one
- JavaScript for people who are in a hurry
- Some advice on how to give a presentation that doesn't suck – part three
- Some advice on how to give a presentation that doesn't suck – part two
- Some advice on how to give a presentation that doesn't suck – part one
- The Monte Carlo method for cross-browser CSS
- Introducing BISON - Binary Interchange Standard and Object Notation
- The singleton design pattern in JavaScript
- More articles
-
Archive
- October 2009 [2]
- July 2009 [1]
- June 2009 [3]
- May 2009 [1]
- February 2009 [1]
- January 2009 [1]
- December 2008 [1]
- November 2008 [3]
- October 2008 [2]
- September 2008 [2]
- August 2008 [1]
- July 2008 [6]
- June 2008 [1]
- May 2008 [1]
- April 2008 [3]
- February 2008 [2]
- January 2008 [1]
- December 2007 [1]
- November 2007 [1]
- May 2007 [1]
- February 2007 [7]
- January 2007 [1]
- December 2006 [6]
-
Websites and blogs
Back to top
©2009 Kai Jäger. All rights reserved. Click here to email me or read the
legal notice.
4 comments
Write a new comment | Trackback URI for this entry"Multithreaded toolkits: A failed dream?"
http://weblogs.java.net /blog/kgh/archive/2004/10/mult ithreaded_t.html
What it tells you to do is "hey, concurrency is not my job, do it the best way you seem feasible (hint: message passing).
Having developed huge GUI apps in the last 6 years in both Swing and SWT/JFace (which is also "not thread safe") I can tell you - there is nothing wrong with it. On the contrary it helps you manage concurrency at the right place and with the right tools (worker threads, jobs and queues).
This is still even more valid when you say "developers aren't concurrency experts". If this is true, you need a simple model. Shared-memory model + locks is NOT a simple model. In fact developers aren't shared-model-concurrency experts because the model becomes incomprehensible for anything more than 2 (shared) objects and 3 threads. Your typical form has anything from 20 to 50 objects in a tree and having even one "bg" thread doing what it likes with your objects is asking for the premature white hair syndrome. The message passing model is by far more manageable and easier to work with.
So I wouldn't say "library designers can't get it right" - because they do get it right eventually. The problem is - the library will not guard you against yourself (and the deadlocks introduced by you). Consider the "not thread safe" decision - a favor. BTW, I am not aware of any modern UI framework that is thread safe.
Write a new comment
<strong>,<em>,<cite>and<code>. Links, email addresses and line breaks are parsed automatically.