Program A:
public void startThreadPool2(boolean flag) {
while(flag) {
Runnable run = new Runnable() {
@Override
public void run() {
System.out.println("running");
}
};
service.execute(run);
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
Program B:
public static void main(String[] args) {
SentimentAnalyse sentimentAnalyse = SentimentAnalyse.getInstance();
sentimentAnalyse.startThreadPool2(true);
}
Program C:
public static void main(String[] args) {
//how to stop the while loop
}
A while loop keep running and I don't know how to stop it in another program.
//update Your ways maybe all works, I find my singleton don't work due to eclipse use different class loader in different program.
flagis passed by-value so the loop will run forever or not at all. In addition,while (flag) { if (flag == false) break; ... }is redundant.mainmethod of a program C or not?