I have a for loop which runs based on value of boolean variable.
public class LoopClass{
..
private boolean[] toInterrupt = new boolean[];
public boolean getValue() {
return toInterrupt[0];
}
public void setValue(boolean newValue) {
toInterrupt[0] = newValue;
}
}
public method abc{
for loop{
if (getValue()){
break:
}}}
I want to interrupt this loop through servlet:
public class interruptServlet exetnds HttpServlet {
LoopClass = lp = new LoopClass();
lp.setValue(true)
}
Even after executing servlet, boolean toInterrupt[0] always remain false. How can i change boolean value through servlet to stop the loop ?
interruptServletis running in another thread (as I assume it is), you need to properly manage the multi-threaded access to the variable to avoid data consistency issues. BTW, please, post the code as close as possible to what you're actually doing, so volunteers can help you better; the one you posted doesn't compile.LoopClass, it won’t affect the value in some other existing instance.