Last active
January 20, 2021 11:59
-
-
Save maxandersen/f00ebc91e3623bd02ad74abc4bb3db5b to your computer and use it in GitHub Desktop.
Example on jbang enabling graalvm -truffle / espresso feature
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
///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