Currently I am working on a Swing application in Java. Lets call this program Simulator. My task is to deliver packages to their destination by trucks. I have a thread which calculates scheduling of the trucks(which package when to deliver).This thread can run in some cases very long. In a second thread(calculator thread) I am calculating the step of simulation. These two threads should communicate with each other. The algorithm thread sends plans and trucks to the calculator thread and calculator thread sends back free trucks to the algorithm thread. The simulation ends when the calculator thread ends its work. My question is related to drawing of the simulation. Where should a call the drawing of the components? In the same thread where the steps are calculated? Third thread for drawing? Any other possible options?
Asked
Active
Viewed 72 times
0
-
2Use `SwingWorker`, seen [here](http://stackoverflow.com/search?tab=votes&q=user%3a230513%20swingworker). – trashgod Jul 09 '14 at 21:02
1 Answers
0
Yes, I'd use a separate thread for drawing. Do the drawing you need in an infinite loop then call Thread.sleep(1000)
to make it update approximately once a second.

dimoniy
- 5,820
- 2
- 24
- 22