Async task calling sync task, thread-safe?

Discussion in 'Plugin Development' started by LucasEmanuel, May 10, 2013.

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

    LucasEmanuel

    Hi, i was looking at the wiki regarding the scheduler and saw this:
    At the bottom of the page
    http://wiki.bukkit.org/Scheduler_Programming

    So, would it be safe to do something like this to stop the server from getting frozen in case there is a bad connection to the database:
    Code:
    plugin.getServer().getScheduler().scheduleAsyncDelayedTask(plugin, new Runnable() {
        public void run() {
            result = mysqlserver.getData();
         
            plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
                public void run() {
                    plugin.addData(result); // Calls bukkit methods etc
                }
            });
        }
    });
     
  2. Yes, you can totally do that, it's designed for that.
     
  3. Offline

    LucasEmanuel

    Nice :) Thank you :)
     
Thread Status:
Not open for further replies.

Share This Page