why do i need EventQueue to start a new thread in java EDT? (JAVA)
Did I get it right? EDT is the main thread of GUI. To start a long operation, it's preferred开发者_C百科 to run it in new thread. So why do we need to use EventQueue for that? Why can't we simply create and run new thread just like in non-Swing programs?
There is nothing that says you need to use the EventQueue if you are running a long running operation in the background. The purpose of the queue here is to utilize if you have to update the UI that the long running process is complete.
When the process is complete you would put some kind of runnable notification on the Event Queue to notify the UI of completion.
No, the EDT is essentially running on the main thread implicitly. You don't "move" the EDT. Rather, if you want to work off of the main thread, and off of the EDT, you do as you say and start your own thread.
Take a look at SwingWorker. It's a common mechanism to help facilitate this.
精彩评论