The point of this thread is so I can learn the most optimized way to handle a task and whether multithreading in this scenario improves or decreases performance. Anyways I have a private LinkedList inside one of my objects which holds objects that denote a specific task a player needs to complete. Every one hour I then change the tasks for every player and I am wanting to know if its better to do this on the main thread or if its better to do it asynchronously.
It firsts clears the list then runs an algorithm I made to pick randomly tasks and add the newly created task objects to the list for every player in my game. Since this is on the main thread when this happens my games server cant process any other info till its complete. I did optimize it so it should be fast and should work either way however this is more about me wanting to learn the optimal solution then just making it work.
So I could either run everything on the main thread or I could make my linkedList's getter synchronized and run that algorithm on a separate thread. How much overhead do synchronized methods produce especially if they are called often? I cant use a ConcurrentSkipListSet since it is similar to a normal Set where I cant access a specific index with .get() which means I would need to do a lot of looping which seems worse than the other 2 options. What is the best methodology here and going forward for me to decide when its better to use synchronized with multiple threads vs just using the main thread?