Solved Optimal interval for syncing data between plugin and storage.

Discussion in 'Spigot Plugin Development' started by chmod_777, Jan 13, 2020.

  1. Hi,
    I recently recoded my storage implementation to fetch a list of all entries and using that to do all getting and setting instead of doing logic straight from the storage. Because of this, I need to sync the data from my plugin to storage on a timer, but I'm not sure at what interval my 'syncEntries()' method should be called.

    this is my doSync() method in my Main class:
    Code (Java):
        public void doSync(){
            Thread t = new Thread(() -> {
                    try {
                    } catch (InterruptedException e) {
                    } finally{
    The hex value is set to 5 minutes in milliseconds. Should it be more frequent to be safe?
  2. nvm, i'm just going to let the server admin decide that :)
  3. This is useless, it will basically always returns true.
    Also, Thread.sleep isn't safe in a Bukkit spigot, it will freeze the whole server and plugins. Do not use Thread.sleep for safety reasons.
    Just some tips!
  4. hes in a separate thread. everything hes done is fine.

    @op i should suggest using bukkits thread pooling. you can run BukkitRunable#runTaskTimerAsync or whatever its called or just runAsyncTask with a while loop and pause the thread like you do now. this way, the program will properly shut down when plugins are disabled automatically for convenience.

    /e actually runtaskasync and pausing the thread may have unintended side effects because of the pooling.

    set the timer to 5 minutes in ticks.
    • Agree Agree x 1