Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!border3.nntp.dca.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail From: Lew Newsgroups: comp.lang.java.programmer Subject: Re: I need a different approach - suggestions please Date: Tue, 26 Jun 2012 16:44:57 -0700 (PDT) Organization: http://groups.google.com Lines: 86 Message-ID: References: <8a5cafca-755d-4ac2-8ea8-c152e39ad511@googlegroups.com> <4fea2ed5$0$292$14726298@news.sunsite.dk> <104e9655-ad13-4aa9-a7d2-76dc5a2c25a1@googlegroups.com> <4fea4752$0$292$14726298@news.sunsite.dk> NNTP-Posting-Host: 69.28.149.29 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1340755210 29178 127.0.0.1 (27 Jun 2012 00:00:10 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Wed, 27 Jun 2012 00:00:10 +0000 (UTC) In-Reply-To: <4fea4752$0$292$14726298@news.sunsite.dk> Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=69.28.149.29; posting-account=CP-lKQoAAAAGtB5diOuGlDQk0jIwmH0T User-Agent: G2/1.0 Xref: csiph.com comp.lang.java.programmer:15635 Arne Vajh=F8j wrote: > Lew wrote: >> Arne Vajh=F8j wrote: >>> Lew wrote: >>>> markspace wrote: >>>>> bilsch wrote: >>>>>> Many things are because I mimic what I see in other programs... I >>>>>> hope I can finish this project without understanding threads >>>>> >>>>> >>>>> Yeah, that's an issue. When teaching someone, is it better to let th= em >>>>> do it the simplest, but wrong, way? Or should you teach them to writ= e >>>>> code they don't understand, but promise too "explain it later?" >>>>> >>>>> I'm actually in the latter camp at the moment. I'd rather see you co= py >>>>> and paste good code, than let you get into the habit of writing bad c= ode >>>>> that you feel you understand. It a style of learning thing, more tha= n a >>>>> programming thing, but I think it's better to get you into the habit = of >>>>> looking at correct code now, so it doesn't seem strange when you see = the >>>>> correct version later. >>>>> >>>>> OTOH, it's not going to adversely effect your small programs. The >>>>> chance of you hitting a threading error in such a small program is >>>>> virtually nil. Just be aware that: 1. the code really is wrong, and = 2. >>>>> you'll have to learn threads eventually. >>>> >>>> They've already hit a threading error. >>>> >>>> How is that "virtually nil" chance? >>> >>> Usually "hit [by] an error" means actually impacted by the error. >>> >>> I did not see any case of such. >> >> Have you run the OP's code? >> >> On a multi-processor system? > > I had not. >=20 > Now I have. >=20 > I expect OP to have too. >=20 > The chance of actually getting a problem by starting > the GUI in main thread instead of event thread is pretty > small. >=20 > Otherwise the wrong way of doing it would not have > been used for so many years. Not so. Those many years, Swing programs were running on single- processor machines for the most part. Cache coherency and such=20 issues were non-existent. Nowadays many machines are multi-processor=20 and thread bugs are more likely to be visible. If it were so safe, then it wouldn't be "the wrong way of doing it". You are expressing the great bad approach to the concurrency problem: "I don't see a problem in the last two or three times I ran the program,=20 therefore there is no problem." This is the attitude that foments so many concurrency bugs. Concurrency bugs by nature are intermittent, unpredictable and=20 inconsistent. Your test proves nothing except that you have fallen into=20 a classic trap. OP: Don't learn the wrong way. Learn the right way. The fact you don't=20 see a bug in the first two or dozen times you run the program means=20 nothing with concurrency issues. Rule for Swing: DO GUI ACTIONS ONLY ON THE EDT! That's that. --=20 Lew