Hi all,
I know, the greenfoot APIs aren't thread safe. But, I often use another thread to save and load the highscore(s), and I now do it this way:
I didn't put the code in where I create a new thread, but I guess that's doesn't add much to my question.
I hope somebody can give me some advice.
// this is all in a subclass of World
private volatile ScoreBoard scoreBoard;
private volatile boolean loaded;
protected synchronized void setScoreBoard(ScoreBoard board)
{
scoreBoard = board;
loaded = true;
}
public void act()
{
if (loaded) {
addObject(scoreBoard, someX, someY);
}
}
private class LoaderThread implements Runnable
{
public void run()
{
ScoreBoard b = new ScoreBoard(arguments);
setScoreBoard(b);
}
}

