You can not. You cannot change the value of a local variable from another thread.
However, you can use a mutable type with a field intand pass it to a new stream. For instance:
public class MutableInt {
private int value;
public void setValue(..) {..}
public int getValue() {..};
}
(Apache commons-lang provides a class MutableIntthat can be reused)
: public static. : , , synchronized AtomicInteger, .