Running Synchronized Code Inside an Async Task

Discussion in 'Plugin Development' started by kmecpp, Feb 10, 2015.

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

    kmecpp

    Hopefully some people still use these forums! I need to spawn in an entity with an asynchronous task and I managed to achieve this by using a nested sync task inside of my async one, but i was curious as to how to do this without Bukkit schedulers, just pure Java. Does anyone have any ideas on how i could do that?
     
  2. Trust me, plenty of people still use these forums. ;) What is your code so far? Could I see it?
     
  3. Offline

    xTrollxDudex

    There is no thread safe way to do it other than that, unless you want to actually go deeper and see what is going on in the background.

    If you have thought over this, and you REALLY want to do it, there is a Queue in net.minecraft.server.MinecraftServer called processQueue, the instance of MinecraftServer can be obtained using CraftServer. Add your runnable to that queue and it will run it on the primary thread.

    Otherwise, do not try doing this with pure java - entities and worlds are not thread safe. Using sync tasks in an async task is perfectly fine, although I fail to see the reason behind doing such a thing asynchronously.
     
    Last edited by a moderator: Feb 10, 2015
Thread Status:
Not open for further replies.

Share This Page