/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,
- Drop table using Java JDBC Template
- Java - Check if array contains the value
- YAML Parser using Java Jackson Library Example
- Java Jackson ObjectMapper Class with Examples
- Get Client IP address from HTTP Response in Java
- How to Word-Warp Console logs in IntelliJ
- Exception in thread main java.lang.NoClassDefFoundError: package javaClass
- Setting Java_Home Environment variable on Windows Operating System
- Fix: Maven - Failed to execute goal - Compilation failure - Source/Target option 5 is no longer supported. Use 7 or later
- Java SE JDBC Select Statement Example
- How to extract Java Jar/War/Ear files in Linux
- java: unclosed string literal [Error]
- [Solution] Exception in thread main java.util.EmptyStackException
- Read YAML file Java Jackson Library
- What Java version is used for Minecraft 1.18
- [Java] How to throws Exception using Functional Interface and Lambda code
- [Program] How to read three different values using Scanner in Java
- Java 8 Predicate Functional Interface Examples
- Display Era details (AD BC) in Java Date using SimpleDateFormat
- Convert String Date to Date Object in Java
- Struts 2 Hello World Example in Eclipse
- Read a file using Java 8 Stream
- Java - How to set custom thread name?
- IntelliJ: Error: Could not find or load main class, java.lang.ClassNotFoundException
- java: ']' expected error [fixed]
More Posts:
- List of Java Simple Date Formats (Cheatsheet) - Java
- Python Program To Calculate Simple Interest (SimpleInterest.py) - Python
- INSTALL_FAILED_INSUFFICIENT_STORAGE Android Error - Android
- Simple Struts 2 Tutorial in eclipse with tomcat 7 server - Java
- Hide files and folders on Mac OS X - Mac-OS-X
- [Solution] The connection to the remote PC was lost, preparing to reconnect - Windows RDP - Windows
- Make Bootstrap Button look like a link - Bootstrap
- How to Copy Entire Directory to another Directory in Linux - Linux