Differences between SwingWorker and Executor

前端 未结 2 588
猫巷女王i
猫巷女王i 2021-02-15 15:25

I am using SwingWorker to execute some heavy load tasks on an application I am making . Although today I got across the Executor class and this example :

Executo         


        
相关标签:
2条回答
  • 2021-02-15 15:56

    The SwingWorker has additional methods process() and done() which are automatically executed in the event dispatch thread. This comes in handy if you plan to display your progress or final results in a user interface.

    0 讨论(0)
  • 2021-02-15 16:20

    1) SwingWorker is created as bridge betweens Java Essentials Classes and Swing by implements Future, and quite guarantee that outoput from methods process, publish and done will be on EventDispatchThread

    2) you can invoke SwingWorker from Executor, this is most safiest methods how to create multithreading in Swing by implements SwingWorker

    3) notice carefully with number or thread, because Executor doesn't care somehow about SwingWorkers life_cycle

    4) another important notice and here

    5) for listening states from SwingWorker you have to implements PropertyChangeListener

    0 讨论(0)
提交回复
热议问题