Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ExecutorService vs Swing Timer

Tags:

java

timer

swing

I've been reading Filthy Rich Clients lately and noticed that, although the version of Java is 6, there is no mention of the Concurrent Framework. So, they talk about java.util.Timer and javax.swing.Timer but not about the ExecutorService.

I read about the advantages of ExecutorService in the question "Java Timer vs ExecutorService" and decided to use the latter over the former. But the book talks about javax.swing.Timer and it's advantages of being specific for Swing development.

So, does this mean that, for Swing development (animating buttons etc.), javax.swing.Timer is still a better choice or is there a relevant class in the new Concurrent Framework that replaces it?

like image 477
pek Avatar asked Dec 18 '22 09:12

pek


1 Answers

Well the Swing Timer at least runs on the EDT so you do not have to wrap everything with calls to invokeLater. It also ties nicely in with Swing as it uses Actions, ActionListeners and other Swing related classes.

I'd stick with Swing Timer for Swing related tasks and use the new concurrent package for things that does not involve updating the GUI.

Have a look at Using Timers in Swing Applications as it might contain more information to swing (sorry) the decision.

like image 126
willcodejavaforfood Avatar answered Dec 28 '22 16:12

willcodejavaforfood