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?
What is the best approach to make a few threads which perform some action
Share
java.util.Timerworks 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 (e.g. usingnotify()).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.