All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cn.nukkit.scheduler.AsyncWorker Maven / Gradle / Ivy

Go to download

A Minecraft Bedrock Edition server software implementation made in Java from scratch which supports all new features.

There is a newer version: 1.6.0.1-PN
Show newest version
package cn.nukkit.scheduler;

import cn.nukkit.InterruptibleThread;

import java.util.LinkedList;

/**
 * @author MagicDroidX (Nukkit Project)
 */
public class AsyncWorker extends Thread implements InterruptibleThread {
    private final LinkedList stack = new LinkedList<>();

    public AsyncWorker() {
        this.setName("Asynchronous Worker");
    }

    public void stack(AsyncTask task) {
        synchronized (stack) {
            stack.addFirst(task);
        }
    }

    public void unstack() {
        synchronized (stack) {
            stack.clear();
        }
    }

    public void unstack(AsyncTask task) {
        synchronized (stack) {
            stack.remove(task);
        }
    }

    public void run() {
        while (true) {
            synchronized (stack) {
                for (AsyncTask task : stack) {
                    if (!task.isFinished()) {
                        task.run();
                    }
                }
            }
            try {
                sleep(5);
            } catch (InterruptedException e) {
                //igonre
            }
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy