Synchronous versus asynchronous tasks
A task can be run either synchronously or asynchronously. Simply put, when a synchronous task is executed, it must be completed before the server can continue running normally. An asynchronous task can be running in the background while the server continues to function. If a task accesses the Bukkit API in any way then it should be run synchronously. For this reason you will rarely run a task asynchronously. The advantage of an asynchronous task is that it can complete without causing your server to lag. For example, writing data to a save file can be done asynchronously. Later in this chapter, we will modify the
Warper
plugin to save its data asynchronously. As for the plugin AlwaysDay
, we must run the task synchronously because it is accessing the Bukkit API.