Solved Update checking different thread

Discussion in 'Spigot Plugin Development' started by MrGeneralQ, Feb 13, 2020.

  1. MrGeneralQ

    MrGeneralQ Previously qintinator
    Supporter

    Good morning everyone

    Some gentle person reached out to me to inform me that one of my plugins is checking for updates on the main thread. I understand his concern, but I only check for newer versions once on in the onEnable(). Would it really be necessary to do this check on a different thread, even if it is once?
     
  2. Well if every plugin just checked for update in on enable method then your server would start 5 times slower, there's nothing hard in making it async and that would be a recommended way to do it.
     
    • Like Like x 1
  3. MrGeneralQ

    MrGeneralQ Previously qintinator
    Supporter

    Is there any source regarding this conclusion?
     
  4. It won't be 5 times slower, but it will add time to it, as an I/O operation have to complete for each plugin before moving on to the next one, and obviously you should know that all I/O operations take a lot of time, in comparison to just reading from RAM.

    An even bigger issue arises if the remote server (be that Spigot or your own server) goes down. Then, you'll have to wait for the HTTP connection to timeout before it moves on to the next plugin. This can take minutes. Java has an infinite timeout by default, however, I'm not sure whether Spigot adds one, as they do change some stuff to do with HTTP connections (i.e. the user agent). Obviously you can see from this why you should perform the request async: I don't want to have to wait minutes for my server to start just so your plugin can fail to perform an update check in the case of an outage
     
    • Like Like x 1
  5. Strahan

    Benefactor

    Source: common sense

    If you have a process that can take time, and can be shunted off the main thread to prevent blocking, why would you not do that?
     
    • Like Like x 3
  6. MrGeneralQ

    MrGeneralQ Previously qintinator
    Supporter

    Thank you all for your feedback. It does make sense indeed. In the meantime I added the task on my todo lane for the next release. Thank you all