Can I return a thread to being synchronous?

Discussion in 'Plugin Development' started by Tythus, Jun 23, 2014.

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

    Tythus

    I made a thread asynchronous as it was going to be reading lots of files but noww I want to translate the UUID's I'm getting from the files is there any way I can do this inside of bukkit?
     
  2. Offline

    mythbusterma

    You can make the a future on the main thread that asks for the result from your thread, or you can fire an event, or you can use thread-safe methods.

    There is no way to make a thread that is asynchronous synchronous, as there is only one main (synchronized) thread.
     
  3. Offline

    1Rogue

    Define "thread", you mean a runnable? Callable? Class that actually extends java.lang.Thread?
     
  4. Offline

    Tythus


    So currently right now I have lots of text files with data in them attached to players UUID's what my script does is it makes an async thread using the bukkit scheduler that gradually opens and reads through all of the data over 20-30 seconds.

    It then finds the data that fills my query I can then return their UUID through a chat message with the relevant data "56dba409-4d9a-4d00-86b5-30fe80188a4f has jumped the most at 57 times out of the entire server" I would rather I returned "Bob has jumped the most at 57 times out of the entire server".

    Until now I have been using the built in method but naturally I can't do that if it's async as it isn't thread safe.
     
  5. Offline

    mythbusterma

    If the player is on the server, Bukkit.getPlayer(UUID id) shouldn't be blocking (correct me if I'm wrong, 1Rogue)
     
  6. Offline

    1Rogue


    Pretty much any method in java is blocking. Bukkit.getPlayer() works on the players that are currently online, it doesn't do an online lookup.


    Note that async in bukkit doesn't make your runnable a "thread", it runs the runnable in a thread reserved in a scheduler service known as a thread pool.

    You should be caching your player values instead of using the UUID lookup online for every operation. If they have played before on the server, you don't need a UUID fetcher or name fetcher, Bukkit.getPlayer() will work fine.
     
    mythbusterma likes this.
  7. Offline

    Tythus

    Unfortunately the player might be offline and that was blocking when I tried it on my plugin

    oh no don't mind me I think it was an issue with a build as on latest build I'm not getting the problem don't mind me

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
Thread Status:
Not open for further replies.

Share This Page