Question about scheduleSyncRepeatingTask

Discussion in 'Plugin Development' started by Mr. Sandwich, Nov 23, 2017.

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

    Mr. Sandwich

    So I use scheduleSyncRepeatingTask for a lot of things, mainly to run different code sections for players in a hashmap and basically I have come to realize that it's not really server friendly in terms of lags so I have been wondering if for example the following code can be improved or if there are ways and tricks to make scheduleSyncRepeatingTask more friendly.
    Code:
        @Override
        public void onEnable() {
            Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() {
                @Override
                public void run() {
                    for (LivingEntity living : hashmap.keySet()) {
                        //stuff
                    }
                }
            }, 3, 3);
        }
    
     
  2. Online

    timtower Administrator Administrator Moderator

    @Mr. Sandwich Run it less often.
    That is the main thing.
    And the amount of stuff that you are doing should be limited as well.
     
  3. Offline

    Mr. Sandwich

    kk
     
  4. Offline

    MightyOne

    @Mr. Sandwich to me itd be more interesting what exactly //stuff is
     
  5. Offline

    Unknown123

    Don't use it. Use runTaskTimer and BukkitRunnables. Also use 3L instead of 3. So This would be better.
    Code:
    new BukkitRunnable() {
                @Override
                public void run() {
                    for (LivingEntity living : hashmap.keySet()) {
                        //stuff
                    }
                }
            }.runTaskTimer(plugin, 3L, 3L);
     
Thread Status:
Not open for further replies.

Share This Page