I am unable to understand the use of states in Apache Flink. As far as my understanding, states maintain variables values during the execution of a Flink program. I think the same thing can be achieved through a class variable.
For instance, if I declare a class variable "someCounter" and increment its value in some Map function, then the "someCounter" value is retained during the course of the code execution, then why do we need an expensive state to maintain the similar values as mentioned in the example on this link: https://ci.apache.org/projects/flink/flink-docs-stable/dev/stream/state/state.html#tab_java_0 ?
static class abc extends RichMapFunction<X,Y> {
long someCounter = 0;
//ctor
public abc() {};
@Override
public Y map(X x) throws Exception {
someCounter++;
if(someCounter > 1000)
someCounter = 0;
return someCounter;
}
}