Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.List;
- public class LoaderThread extends Thread {
- private boolean running = true;
- private List<ModelOrSomething> waitingResources = new ArrayList<ModelOrSomething>();
- public LoaderThread() {
- this.start();
- }
- public synchronized void addResourceToLoad(ModelOrSomething resource) {
- waitingResources.add(resource);
- }
- public void stopThread(){
- running = false;
- }
- @Override
- public void run() {
- while (running) {
- List<ModelOrSomething> resources = getResources();
- for (ModelOrSomething resource : resources) {
- resource.load();
- }
- try {
- sleep(10);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
- }
- private synchronized List<ModelOrSomething> getResources() {
- List<ModelOrSomething> resourcesForLoading = new ArrayList<ModelOrSomething>(waitingResources);
- waitingResources.clear();
- return resourcesForLoading;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement