|
| 1 | +import java.util.Map; |
| 2 | + |
| 3 | +public class EnvMap { |
| 4 | + public static void main (String[] args) throws Exception { |
| 5 | + System.out.println("Hello world"); |
| 6 | + System.out.println("this is a binary built with native-image via Cosmo Libc"); |
| 7 | + var filter = args.length > 0 ? args[0] : ""; |
| 8 | + Map<String, String> env = System.getenv(); |
| 9 | + for (String envName : env.keySet()) { |
| 10 | + if(envName.contains(filter)) { |
| 11 | + System.out.format("%s=%s%n", |
| 12 | + envName, |
| 13 | + env.get(envName)); |
| 14 | + } |
| 15 | + } |
| 16 | + System.out.println("(sorry for hax)\n\n\n\n"); |
| 17 | + tryThreading(); |
| 18 | + } |
| 19 | + |
| 20 | + public static void tryThreading () { |
| 21 | + // Create and start multiple threads |
| 22 | + Thread t1 = new Thread(new CounterTask("Thread A", 1, 5)); |
| 23 | + Thread t2 = new Thread(new CounterTask("Thread B", 100, 105)); |
| 24 | + Thread t3 = new Thread(new CounterTask("Thread C", 1000, 1005)); |
| 25 | + |
| 26 | + t1.start(); |
| 27 | + t2.start(); |
| 28 | + t3.start(); |
| 29 | + |
| 30 | + // Wait for all threads to complete |
| 31 | + try { |
| 32 | + t1.join(); |
| 33 | + t2.join(); |
| 34 | + t3.join(); |
| 35 | + } catch (InterruptedException e) { |
| 36 | + e.printStackTrace(); |
| 37 | + } |
| 38 | + |
| 39 | + System.out.println("All threads completed!"); |
| 40 | + } |
| 41 | +} |
| 42 | + |
| 43 | +class CounterTask implements Runnable { |
| 44 | + private String name; |
| 45 | + private int start; |
| 46 | + private int end; |
| 47 | + |
| 48 | + public CounterTask(String name, int start, int end) { |
| 49 | + this.name = name; |
| 50 | + this.start = start; |
| 51 | + this.end = end; |
| 52 | + } |
| 53 | + |
| 54 | + @Override |
| 55 | + public void run() { |
| 56 | + for (int i = start; i <= end; i++) { |
| 57 | + System.out.println(name + ": " + i); |
| 58 | + try { |
| 59 | + Thread.sleep(100); // Small delay to see interleaving |
| 60 | + } catch (InterruptedException e) { |
| 61 | + e.printStackTrace(); |
| 62 | + } |
| 63 | + } |
| 64 | + } |
| 65 | +} |
0 commit comments