Skip to content

Instantly share code, notes, and snippets.

@maxandersen
Last active January 20, 2021 11:59
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 maxandersen/f00ebc91e3623bd02ad74abc4bb3db5b to your computer and use it in GitHub Desktop.
Save maxandersen/f00ebc91e3623bd02ad74abc4bb3db5b to your computer and use it in GitHub Desktop.
Example on jbang enabling graalvm -truffle / espresso feature
///usr/bin/env jbang "$0" "$@" ; exit $?
//JAVA_OPTIONS -truffle
//`-truffle` is there to enable graalvm espresso.
// See https://medium.com/graalvm/java-on-truffle-going-fully-metacircular-215531e3f840
// with sdman you can do the following to install:
// sdk install java 21.0.0.r11-grl
// gu install espresso
// gu install native-image ## optional
import java.util.Random;
public class HotSwapDemo {
private static final int ITERATIONS = 100;
public static void main(String[] args) {
HotSwapDemo demo = new HotSwapDemo();
System.out.println("Starting HotSwap demo with Java on Truffle");
// run something in a loop
for (int i = 1; i < ITERATIONS; i++) {
demo.runDemo(i);
}
System.out.println("Completed HotSwap demo with Java on Truffle");
}
public void runDemo(int iteration) {
int random = new Random().nextInt(iteration);
System.out.printf("\titeration %d ran with result: %d\n", iteration, random);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment