/Library/Java/JavaVirtualMachines/zulu-11.jdk/Contents/Home/bin/java
-javaagent:/Applications/IntelliJ
IDEA CE.app/Contents/lib/idea_rt.jar=49386:/Applications/IntelliJ
IDEA CE.app/Contents/bin
-Dfile.encoding=UTF-8
-classpath /Users/code2care/IdeaProjects/multi-tasking/out/production/multi-tasking
MyThread
Exception in thread "main" java.lang.IllegalThreadStateException
at java.base/java.lang.Thread.start(Thread.java:789)
at MyThread.main(MyThread.java:8)
This is Main Thread
This is my Thread
Process finished with exit code 1
✏️ IllegalThreadStateException is thrown to indicate that a thread is not in an appropriate state for the requested operation.
Example, you will see java.lang.IllegalThreadStateException when you are using Multi-Threading in your Java program and you start the same thread more than one!
Example:/**
* Java Code Example: code2care.org
*/
public class MyThread extends Thread {
public static void main(String[] args) {
MyThread thread = new MyThread();
thread.start();
System.out.println("This is Main Thread");
thread.start(); //IllegalThreadStateException
}
@Override
public void run() {
System.out.println("This is my Thread");
}
}

The above code can be fixed by making sure that once the thread is not started multiple times.
More Posts related to Java,
- How to install Java 11 on Mac
- Get Client IP address from HTTP Response in Java
- SharePoint Open in the client application document opens in browser
- How to verify if java is installed on the computer and get version detail
- Java - Check if array contains the value
- Your JBoss Application Server 7 is running However you have not yet added any users to be able to access the admin console
- How to run Java Unit Test cases with Apache Maven?
- What Java version is used for Minecraft 1.18
- List of jar files for Jax-ws (SOAP) based Java Web Services
- [Fix] Java Exception with Lambda - Cannot invoke because object is null
- Convert Instant timestamp into LocalDateTime Java Code Example
- Java - Calculate time taken for the code to execute in milliseconds or nanoseconds
- Create simple struts2 project using maven commands
- Java - PatternSyntaxException
- List of Online Java compiler with console
- Minecraft Java Edition
- How to declare and initialize Array in Java Programming
- [Solved] com.sun.xml.ws.transport.http.servlet.WSServletContextListener ClassNotFoundException
- Java XML-RPC 3.1.x based web service example
- Simple Struts 2 Tutorial in eclipse with tomcat 7 server
- Java 8 foreach loop code examples
- Java -Day of the week using Java 8 DayOfWeek Enum
- Java 8 - Convert List to Map Examples
- Java: TimeZone List with GMT/UTC Offset
- list of jars required for hibernate 4.x.x
More Posts:
- Calculate Area of Square - C-Program
- Open New Terminal Window Using Keyboard Shortcut macOS - MacOS
- Be right back We’re making updates to the Apple Store. Check back soon. - Apple
- Create a large dummy file using Mac OS X terminal command - Mac-OS-X
- Android Studio 1.3 beta now Available for Developers - Android-Studio