Switching threads

Discussion in 'Plugin Development' started by Nogtail, Jan 27, 2014.

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

    Nogtail

    For example if I had thread A and thread B and I want to execute a query on thread B from thread A then return it without pausing execution on thread A what is the best way to do this?
     
  2. Offline

    Rocoty

    Schedule an async task to execute the query, then schedule a sync task to do whatever you want to do with the returned value (if there is one).
     
  3. Offline

    Nogtail

    How would it be done without using the Bukkit scheduler?
     
  4. Offline

    Rocoty

    You would have to do some looping in the main thread to check for new data, which can be added to a list/map/set/other from an async thread.
     
  5. Offline

    xTrollxDudex

    Nogtail
    Take the runnable out of the current thread.
    PHP:
    Thread thread Thread.currentThread();
    Field run Thread.class.getDeclaredField("target");
    run.setAccessible(true);
    Object runnable run.get(thread);

    public class 
    Task implements Runnable {
        public 
    void run() {
            return;
        }
    }

    run.set(thread, new Task())
    Thread t = new Thread(runnable);
    t.start();
     
Thread Status:
Not open for further replies.

Share This Page