xpple/SeedMapper

Threading

Opened this issue · 1 comments

xpple commented

The calculations SeedMapper does can be quite resource intensive. Currently, the /locate loot command will scan the entire world until it finds the desired item - which leaves the client hanging for multiple minutes. Don't get me wrong, this particular example is certainly a design flaw on my end and should be prevented. However, even leaving the client hanging for a few seconds can be very annoying and could in the worst case even lead to the player dying. Hence I suggest to execute the commands on a separate, constant thread.

The reason I open an issue is because I couldn't come up with a good way to do this myself. My idea was to have one thread dedicated to the execution of SeedMapper's commands. Execution in the thread can only be stopped by one of two ways: a set time-out or a new command was executed. I know I could just wrap the logic of each command in something like this

new Thread(() -> {
  // code
}).start();

but I think an approach like this doesn't give me enough controll over the threads that are created. Someone suggested using ExecutorService, but I couldn't get that to work. Let me know if you have any elaborate ideas.

Well the thing is you can't forcefully end a thread so you'd heave to deal with either checking if a thread was interupted all the time or just deal with having little to no control over them. You could have a mechanism to invalidate the result of a thread after it calls back tho to avoid showing the result of an old command