What is the best approach to make a few threads which perform some action asynchronous on JPanel
canvas, and can be controlled form main(...)? What about synchronization techniques?
java.util.Timer
works with tasks. Each task has its own scheduling. You can create task per thread and schedule them appropriately. Each task should be able to send signal to its thread (eg using notify()
).
So, you will achieve this functionality: each task notifies its thread and is scheduled separately. And this system is scalable: timer creates only one own thread, so even if number of your working threads will grow you will have only one additional thread in your system.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.