Skip to content

Instantly share code, notes, and snippets.

@palaashatri
Last active February 18, 2023 18:50
Show Gist options
  • Save palaashatri/1bf0fe54d408f36af9e4b5b4d757c6f1 to your computer and use it in GitHub Desktop.
Save palaashatri/1bf0fe54d408f36af9e4b5b4d757c6f1 to your computer and use it in GitHub Desktop.
Simple demonstration of using Static blocks in Java
package testcache;
public class StaticBlock {
static String prometheusUrl = null;
static String billing_service_name = null;
static {
prometheusUrl = System.getenv("PROMETHEUS_URL");
if (prometheusUrl == null) {
prometheusUrl = "http://prom-prometheus-operator-prometheus.monitoring:9090/api/v1/query?/";
}
bem_service_name = System.getenv("BILLING_SERVICE_NAME");
if (bem_service_name == null) {
billing_service_name = "billingmanager";
}
System.out.println("prometheusUrl: " + prometheusUrl );
System.out.println("billing_service_name : "+ billing_service_name);
}
public static void main(String[] args) {
System.out.println("Main executed!");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment