Use or not use SwingWorker versus regular thread

I have a start and stop button. I want to be able to start and stop the task as many times as the user wants. I was able to work normally with a regular thread by doing wait () when the stop button was pressed, and then notifying () when the start button was pressed to start the stream again. It did a great job. However ... I held out the stream. My boss told me to never expand the thread, and that I should use SwingWorker. But I noticed that SwingWorker can only be executed once. Or can it be executed more than once in the same session .. ?? Can someone help me in the right direction?

+4
source share
3 answers

You can simply create a new instance of your SwingWorker every time you want to run logic. Personally, I do not see much benefit to SwingWorker for your problem, as you described it. Not to say that it will not be good ...

+1
source

You very rarely need to stretch Thread . What you need to do is pass the Runnable constructor to the Thread constructor.

For my tastes, SwingWorker adds too much touch to the code, and should be left on a demo where it works very well.

+3
source

You do not need SwingWorker for what you do. SwingWorker is used for cases when you need to run something in the background thread, update your GUI (for example, progress) without blocking i.

What you did is all right.

0
source

Source: https://habr.com/ru/post/1315925/


All Articles