G
G
Gfd2015-12-19 19:22:53
Java
Gfd, 2015-12-19 19:22:53

Why doesn't Task run again?

I want the task thread to stop when the pause() method is called, and then resume when the if(ChoiceRe.getText()=="Normal") condition is met. But this code doesn't do that
if(ChoiceRe.getText()=="Normal"){
System.out.println("Normal mode started");
normalTime=normalTime*60000;
normalTime=normalTime/100;
f=new FileInputStream("src//application//res//Re//NormalRe//NormalReChild.mp3");
if(pause==true){
task3 = new Task() {
@Override
public Void call() throws Exception {
double TimeStart = 0d;
for (int row = 0; row < 100; row++) {
TimeStart = TimeStart + 0.01;
updateProgress(TimeStart, 1);
try {
Thread.sleep(normalTime);
} catch (InterruptedException e) {
return null;
}
}
return null;
}
};
time.progressProperty().bind(task3.progressProperty());
Executors.newCachedThreadPool().submit(task3);
pause=false;
}else{
task = new Task() {
@Override
public Void call() throws Exception {
double TimeStart = 0d;
for (int row = 0; row < 100; row++) {
TimeStart = TimeStart + 0.01;
updateProgress(TimeStart, 1);
try {
Thread.sleep(normalTime);
} catch (InterruptedException e) {
return null;
}
}
return null;
}
};
time.progressProperty().bind(task.progressProperty());
Executors.newCachedThreadPool().submit(task);
}
Task task2 = new Task() {
@Override
protected Void call() throws Exception {
while(time.getProgress()!=1.0){
if(time.getProgress()==0.03){
try {
Player p=new Player (f);
p.play();
} catch (JavaLayerException e) {}
}
}
return null;
}
};
Executors.newCachedThreadPool().submit(task2);
}
}
public void pause(){
task.cancel(true);
pause=true;
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Konstantin Malyarov, 2015-12-19
@Konstantin18ko

Put the code in correctly, it's not readable.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question