synchronized vs asynchronized scheduled events

Discussion in 'Plugin Development' started by LRFLEW, Sep 4, 2011.

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

    LRFLEW

    What is the difference between BukkitScheduler.scheduleAsyncRepeatingTask() vs BukkitScheduler.scheduleSyncRepeatingTask()?
     
  2. sync tasks run in the same thread as bukkit, they can do all that events can, but a long task will stall the server.
    asynce tasks cannot access most of the bukkit API, but they won't clog up a server if they run a long time.

    Tl;DR

    Quick running task, needs API, use sync task

    Long (200mill+) task, doesn't need api, use async
     
  3. Offline

    LRFLEW

    what about a short, non API using event? Should I use async, sync, or just Java's default one?
     
  4. Offline

    Arkel

    If you aren't calling any API methods, use an Asynchronous task.
     
  5. Offline

    LRFLEW

    k thanks :)
     
  6. Just so @LRFLEW doesn't get the wrong idea, you can access the Bukkit API from an async task but you shouldn't because it's not thread safe. You still have access to it though.
     
  7. Offline

    LRFLEW

    actually, I understood the whole "thead safe" issue (https://github.com/Bukkit/CraftBukkit/pull/442). I posted about this partly because I was also interested in when I should use this vs using Java's built in timer :p.
     
  8. @Adamki11s let's not muddy things. For the purposes of solid, reliable code, you Can't access the API from async, apart from one function (to all who read and want to know which one,see the wiki)
     
  9. Ok :p
    World.getBlockAt(Location);
     
  10. Offline

    LRFLEW

    close :p. World.getBlockTypeID(Location);
     
    Bone008 likes this.
  11. Offline

    Afforess

    It is possible, with effort, to expose more of the API to asynch threads. Spout has API support for setting block data and id's async safely.
     
  12. Offline

    LRFLEW

    How is this thread still alive? :p
    Awesome :). You have put so much work into spout/bukkitcontrib.
    I should have looked for the answer there first, shouldn't have I :p
     
  13. Offline

    Raphfrk

    There may also be other methods which are thread safe. However, as I said on the wiki, unless you know for sure, you should assume that the method isn't thread safe.

    That method may have to load a chunk, if the chunk doesn't exists. It also will pull the Block from the block cache if it already exists. These are not thread safe operations (unless that has changed).

    Ideally, the Bukkit API should tag methods as thread safe/not thread safe.
     
Thread Status:
Not open for further replies.

Share This Page