TreasureHunt and MultiThreading/aSyncDelayedTask

Discussion in 'Plugin Development' started by Taien, Feb 5, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    Taien

    I've been searching around the forums for a way to multithread plugins. Essentially I am trying to make the location selection portion of my TreasureHunt plugin's code run in a separate thread so that it doesn't lag the server by running its search for a location. (This has been a fairly common complaint for me.) I did add a max attempts config option so that it would limit how many times the plugin would loop while searching for a location that fits the server owner's config settings before it gave up, but I know that's only a bandaid for the problem. I've read a few people talking about using aSyncDelayedTask to multithread, but haven't been able to find an example of how this is done. Would anyone have any knowledge of topics I can read on this or plugins that use multithreading that I could decompile or read the source code of to learn from?

    I've googled "How To Create a Thread in Java" and I understand the basics of creating a thread, but wouldn't the thread still not really be separate as its run() method would only be called when the task gets called form the scheduler?

    Any help is greatly appreciated...the plugin is a bit outdated and I've got some work to do adding new features to it that I've been meaning to add for a while.

    Also, if I can't figure this out, I'll probably just end up having it store a boolean for whether or not it should be searching for a location that tick, and then just randomly pick a location only X times per tick or something.

    Anyone? I really need some help with this. :) Could someone at least direct me to some plugins which do use multiple threads so I can take a look at how they do it?

    Ok so now I see that scheduleAsyncRepeatingTask is deprecated. Argh...

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 31, 2016
  2. Just use scheduleSyncRepeatingTask ;-)
     
  3. Offline

    Taien

    scheduleSyncRepeatingTask is already how the code is set up, but while it's searching for a location (it can search up to 1000 times(or whatever the config is set to) if it doesn't find a spot that fits the requirements) it causes the server to hang, so that doesn't seem to run things in another thread. My next idea is to have it only run X searches per tick when it is supposed to be searching, but that seems like a bad way to do it. Is that my only choice?
     
  4. They've added getScheduler().run* methods instead.

    And making a queue and executing it a few chunks at a time isn't a bad idea though.
     
  5. Offline

    Taien

    Yeah, I've pretty much already given up and decided to do it a few attempts per tick instead :) lol. Thanks!
     
Thread Status:
Not open for further replies.

Share This Page