--- dao/DaoAdresseVedligehold/src/main/java/dk/daoas/adressevedligehold/tasks/Task.java 2016/02/03 18:45:33 2903 +++ dao/DaoAdresseVedligehold/src/main/java/dk/daoas/adressevedligehold/tasks/Task.java 2016/02/04 14:40:36 2918 @@ -21,8 +21,8 @@ public String state; } - protected boolean abort = false; - protected TaskState state = TaskState.STATE_QUEUED; + protected volatile boolean abort = false;//mark volatile to make sure value isn't cached by threads + protected volatile TaskState state = TaskState.STATE_QUEUED; protected TaskManager manager; private String errorMsg; @@ -49,7 +49,12 @@ try { taskRun(); - this.state = TaskState.STATE_DONE; + + if (this.state != TaskState.STATE_ABORTED) { //just to make sure we wasn't aborted + this.state = TaskState.STATE_DONE; + } + + } catch (Exception e) { this.errorMsg = e.getMessage(); e.printStackTrace(); @@ -91,6 +96,11 @@ this.abort = true; } + public void doAbort(Exception e) { + this.abort = true; + this.errorMsg = e.getMessage(); + } + public TaskBean getTaskBean() { TaskBean bean = new TaskBean(); bean.id = this.getId(); @@ -107,6 +117,13 @@ return this.errorMsg; } + @Override + public final boolean equals(Object o) { + Task otherTask = (Task) o; + + return this.getId() == otherTask.getId(); + } + /** * @throws Exception *