Java Multitasking (String concatenation)
JavaDoc, JavaDoc, JavaDoc.



package zad2;


That is not a good package name. It should ideally be:

package com.yourmailprovider.username.stringstuffy;


or

package com.yourwebsite.stringstruffy;


This makes it very easy to see from where the used classes are from.



task.start();
...
task.startNewTread();


Why are there two start methods?



public class StringTask implements Runnable


This is odd, your class implements Runnable but is not supposed to be used as a Runnable. Instead it has its own set of methods. I suggest that you do not implement Runnable and instead encapsulate the Runnable as private inner class.



String line;
String letter;
int amount;
boolean isAborted;
TaskState stat;
boolean wasAborted = false;


Why are all these variables package private and not private?



public StringTask(String s, int i)


These are very, very bad variable names. Here are two simple rules for variables naming:


Name a variable after what it contains or is doing.
You are only allowed to use one letter variable names for dimensions (x, y, z).




while (amount &gt; 0 &amp;&amp; !isAborted){
    line += letter;
    amount--;
}


What you want is a StringBuilder. A string concatenation is a very costly operation, everytime you concatenate a string a new String object has to be created (because String is immutable). The StringBuilder instead simply extends its internal buffer.



if(wasAborted == false) stat = TaskState.READY;
else stat = TaskState.ABORTED;


Oh dear, that is awful to read. I know that it looks more complicated, but you really should make a habit out of using braces for ifs:

if (!wasAborted) {
    stat = TaskState.READY;
} else {
    stat = TaskState.ABORTED;
}




public void start (){
    isAborted = false;
    stat = TaskState.RUNNING;
    new Thread(this).start();
    //System.out.println("start");
    //run();
}
public void startNewTread (){
    isAborted = false;
    stat = TaskState.RUNNING;
    new Thread(this).start();
}


Why are there two start methods again? They are even doing the same thing.



public boolean isDone(){
    if (stat == TaskState.READY || stat == TaskState.ABORTED) return true;
    return false;
    }


Now this is a prime example of confusing formatting.



CREATED, RUNNING, ABORTED, READY


What's the difference between READY and CREATED? Why do you care if the task has been aborted or not? Does not clean up its state at some point?



Why is there a separate boolean for if the task has been aborted?