Skip to content

Commit

Permalink
Resolves thread issues
Browse files Browse the repository at this point in the history
Threads were throwing IllegalThreadStateExceptions due to being started while running.
RCA:  When threads are needing to be started, they will reset the run method before starting.
  • Loading branch information
Kirsten98 authored Jun 19, 2020
1 parent bc0cc5b commit 7a73029
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 27 deletions.
3 changes: 0 additions & 3 deletions LyricsForSpotifyApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -2069,10 +2069,7 @@ protected void runStepBasedOnStatus(String status){
break;

case("Check if current song is still playing"):
if (threadControl.currentSongCheckThread == null || threadControl.currentSongCheckThread.isInterrupted() || !threadControl.currentSongCheckThread.isAlive()){

threadControl.startCurrentSongCheckThread();
}
break;


Expand Down
10 changes: 2 additions & 8 deletions StageControl.java
Original file line number Diff line number Diff line change
Expand Up @@ -155,19 +155,13 @@ public void errorStage(String errorMessage, Boolean forLyrics) {
skipSong.setDisable(false);
});

Button retry = new Button("Retry");
retry.setOnAction(retryAction ->{
parent.getCurrentSongInfo();
});

HBox songOptions = new HBox(30);
songOptions.getChildren().addAll(retry,skipSong);
songOptions.setAlignment(Pos.CENTER);
mainPane.getChildren().clear();
scrollPane.setContent(errorLabel);
mainPane.getChildren().addAll(mainMenu,song == null? new Text("No song playing"): song,artist == null? new Text("No song playing"): artist, errorLabel);

// if (threadControl.currentSongCheckThread == null || threadControl.currentSongCheckThread.isInterrupted() || !threadControl.currentSongCheckThread.isAlive()){
parent.threadControl.startCurrentSongCheckThread();
// if (threadControl.currentSongCheckThread == null || threadControl.currentSongCheckThread.isInterrupted() || !threadControl.currentSongCheckThread.isAlive()){
// threadControl.startCurrentSongCheckThread();
// }

Expand Down
35 changes: 19 additions & 16 deletions ThreadControl.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,13 @@ public class ThreadControl{
protected boolean expiredTokenRefreshExit = false;
protected boolean songProgressThreadExit = false;

public ThreadControl(LyricsForSpotifyApplication parent){
ThreadControl(LyricsForSpotifyApplication parent){
this.parent = parent;

}

public void startCurrentSongCheckThread() {

currentSongCheckThread = new Thread(new Runnable() {
@Override
public void run() {
Expand All @@ -24,7 +28,11 @@ public void run() {
parent.isCurrentSongStillPlaying();
}
});
currentSongCheckThread.start();
}


public void expiredTokenRefreshStart() {
expiredTokenRefresh = new Thread(new Runnable() {
@Override
public void run() {
Expand Down Expand Up @@ -69,6 +77,11 @@ public void run() {
}
});

expiredTokenRefresh.start();

}

protected void songProgressThreadStart() {
songProgressThread = new Thread(new Runnable() {
@Override
public void run(){
Expand Down Expand Up @@ -114,22 +127,8 @@ public void run(){
}
});

}
songProgressThread.start();

public void startCurrentSongCheckThread() {
currentSongCheckExit = false;
currentSongCheckThread.start();
}


public void expiredTokenRefreshStart() {
expiredTokenRefreshExit = false;
expiredTokenRefresh.start();
}

protected void songProgressThreadStart() {
songProgressThreadExit = false;
songProgressThread.start();
}

public void resetThreads() {
Expand All @@ -147,6 +146,10 @@ public void resetThreads() {
songProgressThread.interrupt();
}

currentSongCheckExit = false;
expiredTokenRefreshExit = false;
songProgressThreadExit = false;

}

}

0 comments on commit 7a73029

Please sign in to comment.