Results 1 to 4 of 4
Thread: Illegal Thread State Exception!
- 02-23-2012, 08:17 AM #1
Member
- Join Date
- Feb 2012
- Posts
- 23
- Rep Power
- 0
Illegal Thread State Exception!
My Code is as follows:
class Example1 implements Runnable {
Thread t = new Thread(this,"Running Thread:");
public void run(){
t.start();
System.out.println("Running Thread:" + t);
}
}
class ThreadExample{
public static void main(String args[]){
Example1 X1 = new Example1();
Thread.currentThread().setName("Main Thread");
try{
System.out.println(Thread.currentThread().getName( ));
X1.run();
}
catch (IllegalThreadStateException e) {
System.out.println("Illegal Thread State Exception");
}
}
}
It is compiling fine but is giving an error while running the program...
Main Thread
Running Thread:Thread[Running Thread:,5,main]
Exception in thread "Running Thread:" java.lang.IllegalThreadStateException
at java.lang.Thread.start(Thread.java:656)
at Example1.run(ThreadExample.java:5)
at java.lang.Thread.run(Thread.java:680)
Can anyone please explain?
- 02-23-2012, 09:11 AM #2
Member
- Join Date
- Oct 2011
- Posts
- 92
- Rep Power
- 0
Re: Illegal Thread State Exception!
Please remember to use the code tags in future :)Java Code:class Example1 implements Runnable { Thread t = new Thread(this,"Running Thread:"); public void run(){ t.start(); System.out.println("Running Thread:" + t); } } class ThreadExample{ public static void main(String args[]){ Example1 X1 = new Example1(); Thread.currentThread().setName("Main Thread"); try{ System.out.println(Thread.currentThread().getName( )); X1.run(); } catch (IllegalThreadStateException e) { System.out.println("Illegal Thread State Exception"); } } }
- 02-23-2012, 09:16 AM #3
Re: Illegal Thread State Exception!
Read the API for Thread. You can't start() the same Thread more than once.
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 02-23-2012, 10:01 AM #4
Member
- Join Date
- Feb 2012
- Posts
- 23
- Rep Power
- 0
Similar Threads
-
Exception in thread "main" java.lang.IllegalArgumentException: illegal component posi
By powpowpenguin in forum New To JavaReplies: 4Last Post: 09-16-2011, 10:08 PM -
How to release multiple threads from waiting state to runnable state
By Dayanand in forum New To JavaReplies: 2Last Post: 02-14-2011, 02:27 PM -
Thread at wait() state , shared data (volatile? confused ;/ )
By doomsword2001 in forum Threads and SynchronizationReplies: 5Last Post: 02-09-2011, 03:11 AM -
Exception in thread "main" java.lang Exception In InitializerError
By kenzo2009 in forum New To JavaReplies: 4Last Post: 10-25-2010, 07:42 PM -
Exception in thread "Thread-22" java.lang.NoClassDefFoundEthen screen just sits there
By bnh14 in forum Java AppletsReplies: 3Last Post: 11-06-2008, 04:24 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks