In the following code snippet , when i run it throws following exception :-
Exception in thread "main" java.lang.IllegalThreadStateException
at java.lang.Thread.start(Unknown Source)
at com.collections.Threads4.go(SCJP.java:323)
at com.collections.Threads4.main(SCJP.java:312)
class Threads4 {
public static void main (String[] args) {
new Threads4().go();
}
public void go() {
Runnable r = new Runnable() {
public void run() {
System.out.print("foo");
}
};
Thread t = new Thread(r);
t.start();
t.start();
}
}
Can anyone let me know why does this happen ?