i am curious and it is also important for me to know the answer of the question in the title. For example, say, i have created a GUI using swing. My program is a file transfering app that can upload a file to server and download a file from the server. Say, the client has got a feature to chat with one of his/her friend who is also logged on with the server. Say, at some point i am downloading a file from the server. As i am downloading a file from a remote machine it will take some time to download the file completely. Say, it takes 1 minute for example. Now, what i want to know is that, at the time i am downloading a file from the server, is it possible that i can chat with my friend? As, swing is single threaded i am a bit confused that whether is it really possible. May be i am wrong. Help me out, please.
Asked
Active
Viewed 44 times
0
-
1Swing has a thread called the event dispatch thread which handles UI updates and mouse/keyboard events etc. Any costly operation like communication with a chat server, downloads etc. should be done in a worker thread and not on the EDT (which action listeners etc. run on, so spawn a new worker for such things). – Thomas Nov 07 '16 at 16:29
-
Not sure why this was closed as a duplicate. I don't see how that link answers the question about `downloading a file and chatting with a friend`. All it does is confirm that Swing is designed to be single threaded. I would have thought a better link would be the section from the Swing tutorial on [Concurrency in Swing](http://docs.oracle.com/javase/tutorial/uiswing/concurrency/index.html) which explains why Swing is single threaded, but then provides options like using a `SwingWorker` to do a task like downloading a file from a server so you can still chat. – camickr Nov 07 '16 at 18:08
-
This is a nice article about why Swing is NOT multi-threaded: https://community.oracle.com/blogs/kgh/2004/10/19/multithreaded-toolkits-failed-dream – hamena314 Nov 08 '16 at 08:37