flink-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Flavio Pompermaier <pomperma...@okkam.it>
Subject Initialization of static variables
Date Thu, 23 Jun 2016 13:12:36 GMT
Hi all,
I've a Flink job that initialize a static Map in the main program, before
starting any Flink transformation. If I run the job locally that variable
is not empty, running the job on the cluster reset that variable..is it a
bug or am I doing something wrong?
It only works if I initialize that variable in a static statement before
the main, that is:

///////////////// KO EXAMPLE
class ErrorMain {

    private static final Map<String,String> ht = new HashMap<>();

    publis static final main(String[]args){
     ht.put("test","test");
     env.readFile().map(
        ...
       //here ht.get("test") returns null
  }
}

///////////////// OK EXAMPLE
class OkMain {

    private static final Map<String,String> ht = new HashMap<>();
    static{
        ht.put("test","test");
    }
    publis static final main(String[] args){

     env.readFile().map(
        ...
       //here ht.get("test") works
  }
}


Best,
Flavio

Mime
View raw message