Solved Asynchronous Block Access (Read-Only)

Discussion in 'Plugin Development' started by NathanWolf, Dec 9, 2013.

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

    NathanWolf

    I searched for this, and couldn't find an answer for this specific question.

    I know you should never modify blocks in another thread, and generally shouldn't interact with the Bukkit API at all from another thread- but is it OK to just get blocks, and not modify them?

    I guess the other option is to get chunk snapshots from the main thread and pass them to the secondary, but it would be nice to avoid that if read-only access is safe. Maybe I can ensure the chunks are loaded before querying, any tricks like that?

    Thanks!
     
  2. Offline

    Compressions

    NathanWolf Typically, you really should only use async threads when performing resource-intensive tasks that don't need to be timed in harmony with other tasks.
     
  3. Offline

    NathanWolf

    That is what this is- I want to push massive block updates off to an async thread, and queue the changes up to be slowly applied inside a repeating task.

    This would work great, but the block updates rely on checking the current state (e.g. not replacing certain materials).

    Which is why I need to know if it's ok to read block data from another thread, or if I have to create a snapshot first.
     
  4. Offline

    Compressions

    NathanWolf If you can get the block states prior to scheduling the async task, it should work fine; otherwise, you may run into concurrency issues. ChunkSnapshots look like a nice feature as they are thread-safe.
     
    NathanWolf likes this.
  5. Offline

    NathanWolf

    Well, for what it's worth, I took your (semi-)advice and kept it synchronous and simple.

    I basically just break up the work into N-sized batches and grind through it in a repeating synchronous task. I feel like there is some work here I could offload to another thread, but it's probably not worth all the data copying and complexity it would introduce.

    Anyway, this lets me create mega-structures like this without killing the server... so yay! :) Thanks for your help.

    [​IMG]
     
Thread Status:
Not open for further replies.

Share This Page