Fix so downloader doesn't cause infinite loop

This commit is contained in:
drdev
2014-05-28 00:28:40 +00:00
parent c07f8d5e9b
commit 5c2f3ddf85
3 changed files with 12 additions and 6 deletions

View File

@@ -74,7 +74,7 @@ public class Forge implements ApplicationListener {
splashScreen = new SplashScreen();
//load model on background thread (using progress bar to report progress)
new Thread(new Runnable() {
FThreads.invokeInBackgroundThread(new Runnable() {
@Override
public void run() {
FModel.initialize(splashScreen.getProgressBar());
@@ -91,7 +91,7 @@ public class Forge implements ApplicationListener {
}
});
}
}, "Game Startup").start(); //use thread name that starts with "Game" so GuiMobile.isGuiThread() returns false
});
}
private void afterDbLoaded() {

View File

@@ -53,6 +53,13 @@ public class FThreads {
GuiBase.getInterface().invokeInEdtAndWait(proc);
}
private static int backgroundThreadCount;
public static void invokeInBackgroundThread(final Runnable proc) {
//start thread name with "Game" so isGuiThread() returns false on GuiMobile
new Thread(proc, "Game BT" + backgroundThreadCount).start();
backgroundThreadCount++;
}
public static boolean isGuiThread() {
return GuiBase.getInterface().isGuiThread();
}

View File

@@ -28,7 +28,6 @@ import forge.interfaces.IProgressBar;
import forge.interfaces.ITextField;
import forge.util.FileUtil;
import forge.util.MyRandom;
import forge.util.ThreadUtil;
import org.apache.commons.lang3.tuple.Pair;
@@ -60,7 +59,7 @@ public abstract class GuiDownloadService implements Runnable {
public void run() {
//invalidate image cache so newly downloaded images will be loaded
GuiBase.getInterface().clearImageCache();
ThreadUtil.invokeInGameThread(this);
FThreads.invokeInBackgroundThread(GuiDownloadService.this);
btnStart.setEnabled(false);
}
};
@@ -87,8 +86,8 @@ public abstract class GuiDownloadService implements Runnable {
cmdClose = cmdClose0;
onUpdate = onUpdate0;
// Free up the EDT by assembling card list on the game thread
ThreadUtil.invokeInGameThread(new Runnable() {
// Free up the EDT by assembling card list on a background thread
FThreads.invokeInBackgroundThread(new Runnable() {
@Override
public void run() {
try {