11011110110011011001100110011001000110011001100111010001011

March 24, 2007

java.util.Timer, diffs in J2ME & J2SE

Filed under: Programming

I find out the diffs from the game 3DNeedForDrift, it used Timers to call Canvas.repaint().

It causes an Nullexception in Timer.run()->mainloop()->canvas.repaint(), there is one frame with NULL canvas.

Let’s see the differences of Timer’s implement:

[J2ME/MIDP2.0]

class TimerThread extends Thread {
…….
public void run() {
        try {
            mainLoop();
        } catch (Throwable t) {
            // Someone killed this Thread, behave as if Timer cancelled
            synchronized (queue) {
                newTasksMayBeScheduled = false;
                queue.clear();  // Eliminate obsolete references
            }
        }
    }

private void mainLoop() {
        while (true) {
            try {
                       ……..      
               if (taskFired) { // Task fired; run it, holding no locks
               try {
                       task.run();
                    } catch (Exception e) {
                       // Cancel tasks that cause exceptions
                       task.cancel();
                   }

              }
            } catch (InterruptedException e) {
            }
        }
    }
}

[J2SE/1.4.2]

class TimerThread extends Thread {
…….
public void run() {
        try {
            mainLoop();
        } finally {
            // Somone killed this Thread, behave as if Timer cancelled
            synchronized(queue) {
                newTasksMayBeScheduled = false;
                queue.clear();  // Eliminate obsolete references
            }
        }
    }

private void mainLoop() {
        while (true) {
            try {
                       ……..      
               if (taskFired)  // Task fired; run it, holding no locks
                    task.run();

            } catch (InterruptedException e) {
            }
        }
    }
}

===================

In J2ME, the try…catch… block makes the Timer running normally even if the task throws an exception.

But in J2SE, there is none protection, it’s why the 3DNeedForDrift failed running in KEmulator!

crack rt.jar to run the game:

Canvas rotation in KEmu

Filed under: Programming

In High level UI, be sure of the position(Mouse click) transform.

while the canvas show, the rotation will cause Canvas.sizeChange(int, int)

operation new Tracks

Filed under: Programming

New feature in KEmulator. while the game running, u can get all the "new" operaion infos, exactly the right line in source code.

the follow shots, In Eclipse