Skip to content

Instantly share code, notes, and snippets.

@zarinfam
Created July 29, 2019 08:43
Show Gist options
  • Save zarinfam/3f2dd9f8bc561dd4e935e1cfea0c7659 to your computer and use it in GitHub Desktop.
Save zarinfam/3f2dd9f8bc561dd4e935e1cfea0c7659 to your computer and use it in GitHub Desktop.
Created with Copy to Gist
public class PrintTask {
public static final String RESULT_SUCCESS = "SUCCESS_PRINT";
public static final String RESULT_FAILURE = "FAILURE_PRINT";
public static final String RESULT_TIMEOUT = "TIMEOUT_PRINT";
public static final String RESULT_NOTHING = "NOTHING_RESULT";
private String result = RESULT_NOTHING;
public void getResult() throws PrintingException {
while (result.equals(RESULT_NOTHING)) {
synchronized (this) {
try {
wait();
} catch (Exception e) {
throw new PrintingException(e);
}
}
}
if (result.equals(RESULT_SUCCESS)) {
return;
}
throw new PrintingException(result);
}
public void setResult(String result) {
this.result = result;
synchronized (this) {
notify();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment