1
スレッドを一時停止するためにwait()およびnotify()を使用する方法が不明です。私は同期に関する話を読んでいますが、私は自分のインスタンスでそれをやる方法がわかりません。プログレスバーと音楽を同期させる制御をスレッドで一時停止したい音楽プレーヤーがあります。ここで私は一時停止するスレッドがある:ここでは待機を使用してスレッドを一時停止する方法JavaFXに通知する
@FXML private void clickedButton(ActionEvent event){
shuffle.setOnAction(e -> {
artistPane.setText(model.getCurrentSong());
if(firstTime){
//Multithreading with JavaFX. Essentially this other thread will check the slider to make sure its on track.
sliderThread = new Task<Void>() {
@Override
protected Void call() throws Exception {
boolean fxApplicationThread = Platform.isFxApplicationThread();
System.out.println("Is call on FXApplicationThread: " + fxApplicationThread);
//this is an infinite loop because now I only need to make this thread once, pausing and starting it, as opposed to making many threads
for(;;){
Thread.sleep(100);
progressBar.setValue(controller.getPercentageDone());
}
}
};
new Thread(sliderThread).start();
firstTime = false;
}else if(!model.getIsPlaying()){
//I want to start the thread here
}
controller.shuffle(); //this will start the music on the next song
});
は、私はまた、スレッドを一時停止して開始したい後半です:
play.setOnAction(e -> {
controller.play(); //this will pause/start the music
if(!model.getIsPlaying()){
//where I want to pause the thread.
}else{
//I want to start the thread here
}
});