Solved How to run heavy code sync?

Discussion in 'Plugin Development' started by Tim_M, Oct 2, 2021.

  1. Offline


    I have VERY heavy code that needs to run. (It takes about 7 hours to run!) My testing server would always time out and shut down. This can be bypassed by increasing the time-out significantly, but I don't really want to do that. The reason I can't use async is because: 1) It takes even longer to run. 2) I am accessing the bukkit API.

    Any help would be appreciated.
  2. Offline


    Is it something that can be parceled out into batches?
  3. Offline


    @Tim_M Can't you just run it in a CompletableFuture task to fix the first problem and use
    To solve the second problem? Also what API are you accessing? A lot of bukkit API is thread-safe so make sure to check that out.
  4. Offline


    It's not thread safe, when ran async it would cause tons of errors in console which aren't there when not ran async.

    Not sure. I'm saving 10k*10k*256 blocks into files on disk.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
  5. Offline


    @Tim_M Well actually calling getBlock on a loaded chunk is thread-safe so why not on the main thread load chunks which have zero impact if you go about it at a steady pace and then from an async task grab every block and save it. I am not sure if setType is thread-safe keep that in mind you probably won't be able to modify blocks just get their type.
  6. Offline


    Thank you for the response I found and fixed the error. I ended up using the NMS getBlock equivelant, which just so happened to not cause any errors and is much faster. Marking Solved.

Share This Page