Re: [Java-gnome-developer] Multithreaded apps (was: Re: broken link)
Brought to you by:
afcowie
From: Jerry H. <wa...@la...> - 2005-01-11 03:30:40
|
The reason is that only a single thread can be in the UI code at a time. This is true of most UI frameworks, including another popular Java one, SWT. I do not know about Swing, as I don't use it. The proper way to run code that modifies the UI is to dispatch it to the UI thread using the UI thread's mainLoop. invokeLater accomplishes this. It schedules the code to be run later. Typical main loop programming. Does Swing not do this? If swing doesn't do it, likely Swing has synchronization internally: which adds some sort of performance hit. I think the main loop style of programming UI applications is much nicer. It provides a very clean abstraction... it's sort of like sending a message to the UI telling it to do something. On Mon, 2005-01-10 at 23:20 -0300, Joao Victor wrote: > Err... sorry but i didn't understand the problem very well yet. BTW, th= ere's a doc about it here: >=20 > http://java.sun.com/docs/books/tutorial/uiswing/misc/threads.html >=20 > I've read parts of it, but still didn't understand (maybe i'm too sleep= y...). I think the reason > why i didn't understand is because i've used threads many times on Swin= g apps, and i've never used > invokeLater. Let me picture a simple example so we can work on it: >=20 > Suppose you're making a chat client, where you have a List widget showi= ng the online users. > Suppose you have a thread which is listening for new packets. Everytime= this thread receives a > "New user" msg packet, it adds a new user to the List widget, and calls= repaint (i think it's not > necessary to call repaint on this situation, but whatever). >=20 > So in this example there's no use of invokeLater, even though the widge= t is being updated by a > thread. Would this somehow "break" something? I mean... i think i've do= ne that sometimes, never > seen any problem :P >=20 > Cheers, > J.V. >=20 >=20 >=20 >=20 > =09 > =09 > =09 > _______________________________________________________=20 > Yahoo! Acesso Gr=E1tis - Instale o discador do Yahoo! agora. http://br.= acesso.yahoo.com/ - Internet r=E1pida e gr=E1tis >=20 >=20 > ------------------------------------------------------- > The SF.Net email is sponsored by: Beat the post-holiday blues > Get a FREE limited edition SourceForge.net t-shirt from ThinkGeek. > It's fun and FREE -- well, almost....http://www.thinkgeek.com/sfshirt > _______________________________________________ > java-gnome-developer mailing list > jav...@li... > https://lists.sourceforge.net/lists/listinfo/java-gnome-developer --=20 Jerry Haltom <wa...@la...> |