Solved Simple thread question

Discussion in 'Plugin Development' started by Goblom, Jul 28, 2014.

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

    Goblom

    If i were to create a new thread and call sleep inside that thread would that freeze the main thread?
     
  2. Offline

    ZodiacTheories

    Goblom

    I think not, not sure though
     
  3. Offline

    Zettelkasten

  4. Offline

    Onlineids

    Goblom Based on the fact that Thread.sleep pauses only the current thread I doubt it.
     
  5. Offline

    Goblom

    Zettelkasten I want to create a new thread because the scheduler is to mainthread and im a hipster like that.
     
    AoH_Ruthless likes this.
  6. Offline

    Zettelkasten

    Goblom ZodiacTheories:
    It only pauses the currently executing thread, so the main thread will continue running.
     
  7. Offline

    Onlineids

    You missed an oppurtunity for the greatest pun ever:
    I want to create a new thread because the scheduler is to mainthread and im a hipster like that.
     
    ZodiacTheories and Goblom like this.
  8. Offline

    NathanWolf


    You can use the scheduler to make async tasks, which get their own thread.

    In general, it's probably much more efficient to do it that way versus sleeping threads, though I guess it may depend on how frequently you want the task to run.
     
  9. Offline

    Goblom

  10. Offline

    NathanWolf


    Assuming you mean *not* Bukkit only, then I see!

    You can still do that, though- just make it a Runnable instead of a Thread.

    A Runnable can be executed by a Thread or a Bukkit Task, so either way it's useable I think.

    Except that Java lacks a scheduler .. hrm... ok, nevermind :)
     
  11. Offline

    Goblom

    NathanWolf Well, there is "EventQueue.invokeLater(Runnable)"
     
    NathanWolf likes this.
  12. Offline

    NathanWolf

    LOL .. that sounds fancy....

    The main issue I realized, as I was typing that last post, is that you'll design a Runnable differently depending on if you expect it to get invoked one time, and then do its own looping/delaying - versus being invoked several times and doing a little bit of work each time.

    I don't have a great answer to that, I guess. It would be nice if Java had a similar sort of "run repeated task" kind of feature .. seems like EventQueue (new to me!) gets you part of the way there...

    Anywho, since you marked this Solved and have a good solution I'm going to let it be - I can't think of a cross-compatible way to easily do what you're trying to do :)
     
    Goblom likes this.
Thread Status:
Not open for further replies.

Share This Page