That is the title of my Bachelor's Thesis and no, it's not Web related. Unbeknownst to some, Web development has always just been a hobby of mine. Sure, it pays my bills and maybe I went a little overboard when I wrote a book about it, but really, I don't want to be a Web developer forever. That is not to say that there's anything wrong with Web development, it's just that I'm also interested in other stuff. Stuff like multi-core CPUs. Multi-core CPUs are slowly entering the consciousness of developers and many of us fear, that the multi-core trend might bring with it a paradigm shift that could change things dramatically. In my thesis, I examine the impact the multi-core trend will have on the way we write our applications, what the challenges are and how some programming languages and libraries address them. Of course the whole multi-core thing is much too big a topic to cover in depth within the scope of a Bachelor's Thesis, so the thesis really only provides an overview. Also, due to various bureaucratic hurdles and my own stupidity, I only had one month to write the thesis start to finish whilst at the same time working my nine to six day job. So needless to say I'm not entirely happy with the result. But I really should stop the whining and let you be the judge of that.
The thesis is in English and it is made available under a Creative Commons Attribution-Noncommercial-No Derivative license. Please enjoy.
Finding parallelism - How to survive in a multi-core world Revision 1 (PDF-File, 508 KB)
Finding parallelism - How to survive in a multi-core world
Sep 02, 22:55 PM by Kai JägerDegrees, cheerleaders and exposed butt cracks Explicit
Behold, for I am now a Bachelor of Science! Well, maybe not officially (don't have my certificate yet), but I handed in my thesis (I'm doing some last revisions, then I'll publish it here), did my defense and got my grade. The bad news is that being a Bachelor of Science doesn't actually give you any super powers. But apparently search engines do...
...which leads me right to topic number one of today's article: privacy. So I have a new neighbor which is great because my old neighbors were really annoying. They were a couple and all they would ever do was fight. That went on for like a year and now they're gone! Thank Zeus! My new neighbor so far has been very pleasant. But here's the thing: she put her full name on her nameplate and it's a relatively rare name, too. So obviously I had to look her up on <generic search engine>. After all, she might have been a known terrorist or even worse, an animal rights activist. Fortunately, she is nothing of the kind. In fact, she's a cheerleader and cheerleaders I have nothing against. Actually her being a cheerleader could turn out to be annoying, should she ever have to borrow something from me ("Could I borrow some S - A - L - T? What do I want? SALT!").
But not only do I know that she's a cheerleader, I also know her date of birth, her occupation, the name and date of birth of her brother, her hobbies, her favorite movie and tons of other incriminating stuff. When I read all that, I thought: what has this world come to? I didn't have to dig for all that information, it was just there for everyone to see. If I had been really interested in finding out more about her, I could've cross-referenced some of the social networking sites she is registered with and I might have gotten a pretty complete picture of her social life on top of what I had already found out. I didn't dig deeper, because I already felt like a creep for looking her up in the first place. But isn't this crazy? Twenty years ago, there would've been no (legal) way for me to find out any of that stuff and today, we open ourselves up completely without thinking twice. I can think of all sorts of different ways of how I could abuse that information. Most simply, I could just mindfuck her ("What do you do for a living? Wait, let me take a guess. You're a ...", "Sweet mother of Jesus, how did you know?".) Also, if I had the hots for her, I could just play it "Groundhog Day" ("What kind of movies do you like? I like ...", "Really? Me too. Wow, we have so much in common".) I can't say I fully understand the implications of this yet, but what I can say is that it scares the hell out of me. Do we really want to open ourselves up like that to anyone who knows our name?
And now for something completely different. So my hard drive died last week which wasn't overly dramatic because I have backups (and it died with a warning) and I have since replaced it with a shiny new 500 gig Samsung drive. Of course I had to reinstall Windows and all software which is always great fun, but since I'm done with my thesis now it's not like I had something better to do. So when I bought the new drive, I went to a local store that I had also bought most of the components of my current PC from. There, I got to experience the worst customer service ever. Seriously, they could have hit me in the face with a baseball bat and it would've been better than what actually happened. The store works like this: you walk up to a counter, there's a clerk on the other side, you tell him what you want and he gets it for you. Because this is Germany, there's usually a perfect queue in front of each counter, but not this time. This time, both clerks were busy with one customer each, but apart from that, I was the only one in the store. "Great, I'll be back home in an instant" I thought to myself. I couldn't have been more wrong. One of the customers was buying parts for what looked like at least three computers. "Oh well, I'll just go to the other counter" I thought, until I realized that the guy buying the piles of computer parts was standing in the "quick checkout" line. Since I'm a farily uncomplicated person, this didn't really bother me. After all, there was only one person in the line before me. Unfortunately, that person turned out to be an asshole. For one, he leaned against the counter in such a way that his ass would stick out, revealing his butt crack. Secondly, he wanted to buy a DVD drive and it had to be white. That alone wouldn't be an unreasonable request, but he claimed that he had run into problems with all his DVD drives in the past and therefore he hated every DVD drive manufacturer in existence (hint: if you have problems with different drives, it's not the drives, it's you).
The whole discussion went like this: "Well, there are only two manufacturers that make white DVD drives, Samsung and LG". "Samsung makes terrible drives and I heard bad things about LG." "Seriously? We have the least number of returns with Samsung drives". "Oh yeah? Had nothing but trouble with them." "So what about LG?" "Aren't they kinda loud?" "They're definitely louder than the Samsung drives." "I want quiet." "Again, you have to choose between Samsung and LG. There are no other options." "Hmm, what about Liteon?" "They don't come in white" "It's got to be white" "Then Samsung or LG it is." "I've had nothing but trouble with Samsung." "I'm sorry to hear that, but they tend to be very reliable." "At least five of my friends have had serious trouble with Samsung drives." "You want an LG then?" "I dunno. There's really no alternative?" "You can always get a white blind for your drive, but we don't sell those." "Sounds good. So what kind of non-white drive do you recommend?" "Seriously, I've never had any problems with Samsung." "I'm not buying a Samsung." It goes on. After waiting for about half an hour, I left the store and went to another store just up the road where I was served instantly. On my way back home, I passed by the fist store again and I shit you not, they were still serving the same two customers. But now, there were like 15 other customers waiting in line. If I wasn't such a mild tempered person, I probably would've gone berserk just then. Now I sincerely hope they go out of business and as for butt-crack-boy: if he has to go to a computer store to have a conversation, I don't think he needs any additional punishment.
In other news: since the profanity has gotten a little out ouf hand lately, I'm now labeling all blog posts that contain adult language as "Explicit". Users of the iTunes music store should feel right at home.
Aug 07, 19:43 PM by Kai Jäger
...which leads me right to topic number one of today's article: privacy. So I have a new neighbor which is great because my old neighbors were really annoying. They were a couple and all they would ever do was fight. That went on for like a year and now they're gone! Thank Zeus! My new neighbor so far has been very pleasant. But here's the thing: she put her full name on her nameplate and it's a relatively rare name, too. So obviously I had to look her up on <generic search engine>. After all, she might have been a known terrorist or even worse, an animal rights activist. Fortunately, she is nothing of the kind. In fact, she's a cheerleader and cheerleaders I have nothing against. Actually her being a cheerleader could turn out to be annoying, should she ever have to borrow something from me ("Could I borrow some S - A - L - T? What do I want? SALT!").
But not only do I know that she's a cheerleader, I also know her date of birth, her occupation, the name and date of birth of her brother, her hobbies, her favorite movie and tons of other incriminating stuff. When I read all that, I thought: what has this world come to? I didn't have to dig for all that information, it was just there for everyone to see. If I had been really interested in finding out more about her, I could've cross-referenced some of the social networking sites she is registered with and I might have gotten a pretty complete picture of her social life on top of what I had already found out. I didn't dig deeper, because I already felt like a creep for looking her up in the first place. But isn't this crazy? Twenty years ago, there would've been no (legal) way for me to find out any of that stuff and today, we open ourselves up completely without thinking twice. I can think of all sorts of different ways of how I could abuse that information. Most simply, I could just mindfuck her ("What do you do for a living? Wait, let me take a guess. You're a ...", "Sweet mother of Jesus, how did you know?".) Also, if I had the hots for her, I could just play it "Groundhog Day" ("What kind of movies do you like? I like ...", "Really? Me too. Wow, we have so much in common".) I can't say I fully understand the implications of this yet, but what I can say is that it scares the hell out of me. Do we really want to open ourselves up like that to anyone who knows our name?
And now for something completely different. So my hard drive died last week which wasn't overly dramatic because I have backups (and it died with a warning) and I have since replaced it with a shiny new 500 gig Samsung drive. Of course I had to reinstall Windows and all software which is always great fun, but since I'm done with my thesis now it's not like I had something better to do. So when I bought the new drive, I went to a local store that I had also bought most of the components of my current PC from. There, I got to experience the worst customer service ever. Seriously, they could have hit me in the face with a baseball bat and it would've been better than what actually happened. The store works like this: you walk up to a counter, there's a clerk on the other side, you tell him what you want and he gets it for you. Because this is Germany, there's usually a perfect queue in front of each counter, but not this time. This time, both clerks were busy with one customer each, but apart from that, I was the only one in the store. "Great, I'll be back home in an instant" I thought to myself. I couldn't have been more wrong. One of the customers was buying parts for what looked like at least three computers. "Oh well, I'll just go to the other counter" I thought, until I realized that the guy buying the piles of computer parts was standing in the "quick checkout" line. Since I'm a farily uncomplicated person, this didn't really bother me. After all, there was only one person in the line before me. Unfortunately, that person turned out to be an asshole. For one, he leaned against the counter in such a way that his ass would stick out, revealing his butt crack. Secondly, he wanted to buy a DVD drive and it had to be white. That alone wouldn't be an unreasonable request, but he claimed that he had run into problems with all his DVD drives in the past and therefore he hated every DVD drive manufacturer in existence (hint: if you have problems with different drives, it's not the drives, it's you).
The whole discussion went like this: "Well, there are only two manufacturers that make white DVD drives, Samsung and LG". "Samsung makes terrible drives and I heard bad things about LG." "Seriously? We have the least number of returns with Samsung drives". "Oh yeah? Had nothing but trouble with them." "So what about LG?" "Aren't they kinda loud?" "They're definitely louder than the Samsung drives." "I want quiet." "Again, you have to choose between Samsung and LG. There are no other options." "Hmm, what about Liteon?" "They don't come in white" "It's got to be white" "Then Samsung or LG it is." "I've had nothing but trouble with Samsung." "I'm sorry to hear that, but they tend to be very reliable." "At least five of my friends have had serious trouble with Samsung drives." "You want an LG then?" "I dunno. There's really no alternative?" "You can always get a white blind for your drive, but we don't sell those." "Sounds good. So what kind of non-white drive do you recommend?" "Seriously, I've never had any problems with Samsung." "I'm not buying a Samsung." It goes on. After waiting for about half an hour, I left the store and went to another store just up the road where I was served instantly. On my way back home, I passed by the fist store again and I shit you not, they were still serving the same two customers. But now, there were like 15 other customers waiting in line. If I wasn't such a mild tempered person, I probably would've gone berserk just then. Now I sincerely hope they go out of business and as for butt-crack-boy: if he has to go to a computer store to have a conversation, I don't think he needs any additional punishment.
In other news: since the profanity has gotten a little out ouf hand lately, I'm now labeling all blog posts that contain adult language as "Explicit". Users of the iTunes music store should feel right at home.
Elevators are for the elderly and the disabled
There’s an obesity epidemic, and you know why? You can blame it on high fructose corn syrup or our excessive consumption of carbohydrates and saturated fats, or you can just accept the fact that we as a society have become lazy to an extent that is beyond reason.
Where there’s a rant, there’s a story and here it is: So in the city where I live, they have made all underground stations wheelchair accessible by installing elevators. That’s all good, except you never actually see handicapped people on those elevators. Instead, they’re always occupied by young and perfectly healthy people. If elevators were the only means of getting to the surface level, then I wouldn’t mind this at all, but they are not. There’s always a staircase that will get you to the surface just as fast and often faster. What’s so ironic about this is that some of these people may actually be paying good money for a gym membership, but they’re too lazy to walk up a bunch of stairs.
A couple of years ago, I made the decision not to use elevators or escalators anymore, unless I absolutely have to. Apart from the obvious benefits (you can’t get stuck in a staircase and if somebody farts you can run away from the smell), it’s also done a great deal for my overall physical fitness. If that doesn’t convince you, just think about this for a sec: if you have an office job, you probably spend eight or more hours a day sitting down. After that, you should really crave for some exercise but instead, you voluntarily stand in an elevator with a bunch of people who might be crazy and who you might have to spend a substantial amount of time with in the likely event that the elevator should get stuck. This sounds crazy because it is. Still not convinced? Well, listen to this: According to this statistic, walking up one hundred steps equals an energy consumption of 11 kcal. Not bad, considering that it’s not really exercise but a means of getting from one floor to another.

To help spread the word about this, I have made a mockup for a sign that I think should be installed wherever there’s both an elevator and a staircase. Click the image to see a larger (printable) version.
Jul 19, 11:16 AM by Kai Jäger
Where there’s a rant, there’s a story and here it is: So in the city where I live, they have made all underground stations wheelchair accessible by installing elevators. That’s all good, except you never actually see handicapped people on those elevators. Instead, they’re always occupied by young and perfectly healthy people. If elevators were the only means of getting to the surface level, then I wouldn’t mind this at all, but they are not. There’s always a staircase that will get you to the surface just as fast and often faster. What’s so ironic about this is that some of these people may actually be paying good money for a gym membership, but they’re too lazy to walk up a bunch of stairs.
A couple of years ago, I made the decision not to use elevators or escalators anymore, unless I absolutely have to. Apart from the obvious benefits (you can’t get stuck in a staircase and if somebody farts you can run away from the smell), it’s also done a great deal for my overall physical fitness. If that doesn’t convince you, just think about this for a sec: if you have an office job, you probably spend eight or more hours a day sitting down. After that, you should really crave for some exercise but instead, you voluntarily stand in an elevator with a bunch of people who might be crazy and who you might have to spend a substantial amount of time with in the likely event that the elevator should get stuck. This sounds crazy because it is. Still not convinced? Well, listen to this: According to this statistic, walking up one hundred steps equals an energy consumption of 11 kcal. Not bad, considering that it’s not really exercise but a means of getting from one floor to another.

To help spread the word about this, I have made a mockup for a sign that I think should be installed wherever there’s both an elevator and a staircase. Click the image to see a larger (printable) version.
Dynamic-typing and performance
Pretty much by accident I just discovered this video on YouTube, in which James Gosling, inventor of the Java programming language, basically badmouthes Ruby and it's lack of scalability. Twitter (which is written in Ruby) has had some issues, so he might have a point there. But what struck me was the following sentence: "dynamic typing in terms of raw execution performance costs you between one and two orders of magnitude in performance". I usually try not to disagree with people who are between one and two orders of magnitude smarter than me, but in this case I have to.
When Java came out in 1995, it didn't have the high-performance VM it has now. In fact, it was strictly bytecode-interpreted and it had a non-generational garbage collector that would freeze the application whenever a collection was taking place. Java was pretty slow in the beginning and it was often made fun of for that reason. In fact, even today many (ignorant) people associate Java with unresponsive applications. Ultimately, Sun realized that the performance wasn't good enough and so they bought the company that originally developed the Hotspot VM. The funny thing is that many of the concepts that make the Hotspot VM so great were actually inspired by technologies that were originally developed for dynamic languages such as Self (which now is conveniently developed at Sun) and Smalltalk.
Dynamic typing is in fact associated with a performance penalty, but most of this penalty can be overcome by using things like compile-time type-inference and tracing JIT compilers. James Gosling of all people should know that runtime performance isn't a black-and-white thing. A few years ago everybody thought virtual function calls were "several orders of magnitude" slower than static function calls. Now we have tracing JIT-compilers that can inline these calls. To me, it seems like the formerly bullied now becomes a bully himself (just like in real life). Or in other words: shit rolls downhill.
Jul 17, 22:06 PM by Kai Jäger
When Java came out in 1995, it didn't have the high-performance VM it has now. In fact, it was strictly bytecode-interpreted and it had a non-generational garbage collector that would freeze the application whenever a collection was taking place. Java was pretty slow in the beginning and it was often made fun of for that reason. In fact, even today many (ignorant) people associate Java with unresponsive applications. Ultimately, Sun realized that the performance wasn't good enough and so they bought the company that originally developed the Hotspot VM. The funny thing is that many of the concepts that make the Hotspot VM so great were actually inspired by technologies that were originally developed for dynamic languages such as Self (which now is conveniently developed at Sun) and Smalltalk.
Dynamic typing is in fact associated with a performance penalty, but most of this penalty can be overcome by using things like compile-time type-inference and tracing JIT compilers. James Gosling of all people should know that runtime performance isn't a black-and-white thing. A few years ago everybody thought virtual function calls were "several orders of magnitude" slower than static function calls. Now we have tracing JIT-compilers that can inline these calls. To me, it seems like the formerly bullied now becomes a bully himself (just like in real life). Or in other words: shit rolls downhill.
Re: Java Posse #196
Marc Seeger kindly informed me today, that the Java Posse was doing a section (mp3) in their latest episode on my recent blog post Java Swing is not thread-safe. This would have totally slipped past me if it hadn’t been for Marc, so thanks a lot Marc! Also, I would like to thank the Java Posse for linking to my post, although I wish it had been a post that I had put more thought and effort into.
I’m currently writing my Bachelor’s Thesis on concurrency and how different programming languages address the issue. While doing the research for that, I also looked at Java and some of the more popular Java libraries. So I’m approaching this issue from a concurrency point of view and not so much from a Java point of view. Also, I’m by no means a Java, let alone a Swing expert. I have written some Java code that made it into a product, but I don’t normally use Java professionally. I wrote the “Swing isn’t thread-safe” post because I realized that there are all these Java programmers who have never had to worry about thread-safety before, and now they’re told that they have to write multi-threaded code to make use of multi-core CPUs. I believe this spells disaster, not only because Java’s concurrency model is inherently broken (pdf), but also because shared-state-concurrency in general is inherently broken. But even if you ignore this fact for a second and imagine that not only are they writing multi-threaded code, they’re also writing it against GUI toolkits that aren’t thread-safe, I think you will understand what motivated me to write that post.
I realize after listening to the Java Posse episode that my post was way too short and that I hadn’t put enough thought into it. That’s probably also why the Java Posse misquoted me on two separate issues. For one, they quote me of saying that Swing was single-threaded. If you read my post, you’ll realize that I only ever talked about Swing not being thread-safe. Also, at one point they use the quote “shouldn’t we make the GUI faster” which again I neither said nor meant. When I said “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” I was of course talking about application code and not the GUI toolkits. So I guess what lead to the misunderstandings was a lack of clarity on my side and maybe a little carelessness on the Java Posse’s side. Either way, that episode of the Java Posse was very interesting and enlightening, but as far as my blog post goes, they were missing the point. I don’t blame them though because again, things might not have been as clear as they should have been.
What I wanted to discuss in my blog post wasn’t so much whether Swing should be thread-safe or not, but if we can look into our concurrent future with confidence and to be frank with you, I think we’re all doomed. All popular programming languages including Java, C# and C++ build their concurrency model around the concept of threads and locks (actually I should exclude C++ here because it doesn’t have a concurrency model yet). While nobody really knows what the ideal concurrency model is (or if there even is a single ideal concurrency model), most people in computer science agree that threads and locks is not it. I could go into great detail as to why that is, but that’s a topic for a different blog post. So let’s just say that writing non-trivial concurrent applications using threads and locks is extremely difficult and even experienced programmers get it wrong all the time. It usually boils down to either using too much (or too coarse-grained) synchronization which produces sequential bottlenecks or to using too little synchronization which results in race conditions. Both cases are undesirable, but race conditions are actually beyond being just undesirable. They’re evil. In fact, they are so evil, that they sometimes kill people. Now imagine a few years from now, everybody’s writing multi-threaded applications and not only are we using programming languages that are ill-equipped for it, we’re using libraries that aren’t thread-safe. And even worse, most of us don’t even know that the libraries aren’t thread-safe.
In the case of Java Swing, a lot of people will argue that you usually won’t have to mutate the state of your GUI objects from within multiple threads. In fact, it’s generally a bad idea to do so from a software design perspective. This argument however is flawed and I will tell you why. In C++ just like in Java there is an operator called new that allocates memory. Unlike in Java however, a second operator delete exists that you have to explicitly call to free any memory that you have previously allocated with new. If you forget to call delete, you create a memory leak. Not surprisingly, a lot of applications written in C++ leak memory. In my opinion, this isn’t because these applications were written by bad programmers but because the concept of manual memory management is inherently flawed. This really boils down to a question of mentality. C++ trusts the programmer, Java does not. Java is usually very good at taking away the sharp and pointy things. There is no pointer arithmetic, no manual memory management, none of the dangerous fun stuff. What’s very surprising though is that Java still relies on threads and locks for its concurrency model, which, speaking in terms of sharp and pointy things, is a giant syringe filled with concentrated AIDS. The same applies to Swing not being thread-safe. It isn’t so much that there aren’t good reasons for making a GUI library thread-unsafe, it’s just that it doesn’t fit the Java mentality. You can’t twiddle with pointers, but you’re welcome to have a hundred threads invoking methods on a GUI component in an unsafe manner. That just doesn’t seem right.
So should Swing be thread-safe then? I don’t know the answer to that question. What I do know however is that if multi-core is the future (and I do believe that it is), we’re going to need a better concurrency model. The Erlang concurrency model appears to be a strong contender for that position.
I’m currently writing my Bachelor’s Thesis on concurrency and how different programming languages address the issue. While doing the research for that, I also looked at Java and some of the more popular Java libraries. So I’m approaching this issue from a concurrency point of view and not so much from a Java point of view. Also, I’m by no means a Java, let alone a Swing expert. I have written some Java code that made it into a product, but I don’t normally use Java professionally. I wrote the “Swing isn’t thread-safe” post because I realized that there are all these Java programmers who have never had to worry about thread-safety before, and now they’re told that they have to write multi-threaded code to make use of multi-core CPUs. I believe this spells disaster, not only because Java’s concurrency model is inherently broken (pdf), but also because shared-state-concurrency in general is inherently broken. But even if you ignore this fact for a second and imagine that not only are they writing multi-threaded code, they’re also writing it against GUI toolkits that aren’t thread-safe, I think you will understand what motivated me to write that post.
I realize after listening to the Java Posse episode that my post was way too short and that I hadn’t put enough thought into it. That’s probably also why the Java Posse misquoted me on two separate issues. For one, they quote me of saying that Swing was single-threaded. If you read my post, you’ll realize that I only ever talked about Swing not being thread-safe. Also, at one point they use the quote “shouldn’t we make the GUI faster” which again I neither said nor meant. When I said “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” I was of course talking about application code and not the GUI toolkits. So I guess what lead to the misunderstandings was a lack of clarity on my side and maybe a little carelessness on the Java Posse’s side. Either way, that episode of the Java Posse was very interesting and enlightening, but as far as my blog post goes, they were missing the point. I don’t blame them though because again, things might not have been as clear as they should have been.
What I wanted to discuss in my blog post wasn’t so much whether Swing should be thread-safe or not, but if we can look into our concurrent future with confidence and to be frank with you, I think we’re all doomed. All popular programming languages including Java, C# and C++ build their concurrency model around the concept of threads and locks (actually I should exclude C++ here because it doesn’t have a concurrency model yet). While nobody really knows what the ideal concurrency model is (or if there even is a single ideal concurrency model), most people in computer science agree that threads and locks is not it. I could go into great detail as to why that is, but that’s a topic for a different blog post. So let’s just say that writing non-trivial concurrent applications using threads and locks is extremely difficult and even experienced programmers get it wrong all the time. It usually boils down to either using too much (or too coarse-grained) synchronization which produces sequential bottlenecks or to using too little synchronization which results in race conditions. Both cases are undesirable, but race conditions are actually beyond being just undesirable. They’re evil. In fact, they are so evil, that they sometimes kill people. Now imagine a few years from now, everybody’s writing multi-threaded applications and not only are we using programming languages that are ill-equipped for it, we’re using libraries that aren’t thread-safe. And even worse, most of us don’t even know that the libraries aren’t thread-safe.
In the case of Java Swing, a lot of people will argue that you usually won’t have to mutate the state of your GUI objects from within multiple threads. In fact, it’s generally a bad idea to do so from a software design perspective. This argument however is flawed and I will tell you why. In C++ just like in Java there is an operator called new that allocates memory. Unlike in Java however, a second operator delete exists that you have to explicitly call to free any memory that you have previously allocated with new. If you forget to call delete, you create a memory leak. Not surprisingly, a lot of applications written in C++ leak memory. In my opinion, this isn’t because these applications were written by bad programmers but because the concept of manual memory management is inherently flawed. This really boils down to a question of mentality. C++ trusts the programmer, Java does not. Java is usually very good at taking away the sharp and pointy things. There is no pointer arithmetic, no manual memory management, none of the dangerous fun stuff. What’s very surprising though is that Java still relies on threads and locks for its concurrency model, which, speaking in terms of sharp and pointy things, is a giant syringe filled with concentrated AIDS. The same applies to Swing not being thread-safe. It isn’t so much that there aren’t good reasons for making a GUI library thread-unsafe, it’s just that it doesn’t fit the Java mentality. You can’t twiddle with pointers, but you’re welcome to have a hundred threads invoking methods on a GUI component in an unsafe manner. That just doesn’t seem right.
So should Swing be thread-safe then? I don’t know the answer to that question. What I do know however is that if multi-core is the future (and I do believe that it is), we’re going to need a better concurrency model. The Erlang concurrency model appears to be a strong contender for that position.
