Skip to content

Threaded Weather/Time Updates #24

@austinpilz

Description

@austinpilz

Today, the plugin uses the Bukkit scheduler to update the world weather and time using external API calls. This works well when the weather API returns in a timely manner. I've seen a few issues lately across my network where the API calls take a while, and the whole server lags. It took a while to track down, but some thread dumps did the trick.

However, when there's a network interruption, outage, or lag with the HTTP response times, your main thread of the server is left hanging for up to 15 seconds.

The call to the weather API should be done on another thread. Bukkit/Spigot/Paper don't permit you to update in-game attributes (like world or player data) off the main thread. However, this shouldn't be a problem.

  • You can have the craft scheduler periodically run and refresh the data from the API on another thread. It can update plugin-managed variable/map of the weather/time.
  • You have another scheduled task that reads the updated world data from your plugin-managed data structure, and it uses that (on the main thread) to update the world.

With this solution, you'll never have your main thread hanging around waiting for the API call to return.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions