I've recently run into a problem with my code, I have 1 thread executing and running the game, and another thread checking for all events that may have been called in the event:
Example of an Event:
       try {
            if (currentMinigame != null) {
            //Longer code and method execution time would usually be here, 
            //but for the sake of simplicity, I'll just use this
                currentMinigame.onEntityShootBow(e);
            }
        } catch (Exception ex) {
            exitEarly(ex);
        }
The problem is that, at some point, the thread executing the minigame will set currentMinigame to null. At which point, a null pointer will be called on the line: currentMinigame.onEntityShootBow(e);
Is there an easy way of synchronizing ALL of these events? (There are about 25 of them)
I thought of using
Object currentMinigameLock = new Object();
Synchronized(currentMinigameLock)
and putting this through each and every event, but every time I use synchronize; I almost never see a change, and that's a serious amount of code to refactor! Would there be an easier way?
Thanks Guys! -Tom
