Skip to content

Instantly share code, notes, and snippets.

@shannah
Created December 6, 2012 22:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shannah/4229075 to your computer and use it in GitHub Desktop.
Save shannah/4229075 to your computer and use it in GitHub Desktop.
Controller method to run the native towers of hanoi benchmark
protected void onMain_BtnNativeTowerOfHanoiAction(Component c, ActionEvent event) {
final Label towerOfHanoiLabel = this.findLblTowerOfHanoi();
towerOfHanoiLabel.setText("Calculating.... Please wait");
if ( isCalculatingHanoi ){
return;
}
isCalculatingHanoi = true;
Thread t = new Thread(new Runnable(){
public void run() {
NativeTowersOfHanoi calculator = (NativeTowersOfHanoi)NativeLookup.create(NativeTowersOfHanoi.class);
long start = System.currentTimeMillis();
//TowersOfHanoi.move(30, 1, 3);
final int result = calculator.runCalculation();
long end = System.currentTimeMillis();
calculationTime = end - start;
isCalculatingHanoi = false;
Display.getInstance().callSerially(new Runnable(){
public void run() {
towerOfHanoiLabel.setText("Calculation took "+calculationTime+"ms (with result "+result+")");
}
});
}
});
t.start();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment