Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9277625
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T17:09:15+00:00 2026-06-18T17:09:15+00:00

After execution the below code and throwing IllegalMonitorStateException exception. I am getting error as:

  • 0

After execution the below code and throwing IllegalMonitorStateException
exception. I am getting error as:

java.lang.IllegalMonitorStateException
    at java.lang.Object.notify(Native Method)
    at com.blt.ThreadExample.main(ThreadExample.java:21)

I am new in multithreading, I want to use wait() and notify() in the code.

package com.blt;



public class ThreadExample implements Runnable {
    public static void main(String args[])
    {


        System.out.println("A");
        Thread T = new Thread(new ThreadExample());
        Thread T1 = new Thread(new ThreadExample());

        System.out.println("B");
        try
        {
        T.setName("thread 1");
        T.start();
        T1.setName("thread 2");
        System.out.println("C");
        T.notify();

        System.out.println("D");
        T1.start();
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
    }


        public  void run()
{


            synchronized(ThreadExample.class)
            {


        for(int i=0; i<5; i++)
    {

        try
        {
            Thread.currentThread().wait(400);
         System.out.println("Inside run=>"+Thread.currentThread().getName());
         Thread.currentThread().sleep(2000);




        }
         catch(Exception e)
        {
            e.printStackTrace();
        }
      }  
}
}
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T17:09:16+00:00Added an answer on June 18, 2026 at 5:09 pm

    Try this.. and let me know if you have any doudt.

    package com.blt;
    
    public class ThreadExample implements Runnable {
        public static void main(String args[]) {
            Thread T1 = new Thread(new ThreadExample());
            Thread T2 = new Thread(new ThreadExample());
            try {
                T1.setName("thread 1");
                T1.start();
                T2.setName("thread 2");
                T2.start();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    
        public void run() {
    
            synchronized (ThreadExample.class) {
                for (int i = 0; i < 5; i++) {
                    try {
                        ThreadExample.class.notify();
                        System.out.println("Thread going to wait state::"+ Thread.currentThread().getName());
                        ThreadExample.class.wait(400);
                        System.out.println("Thread notified is::"+ Thread.currentThread().getName());
                        System.out.println("Thread going to sleep state::"+ Thread.currentThread().getName());
                        Thread.sleep(2000);
                        System.out.println("==========");
    
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've the code shown below but nothing happens after execution system('mysqldump -u USER -pPASS
The following code is throwing the exception below: URL u = new URL(file://D:/abc.xml); InputStream
I am trying to repeat a code execution after predefined time passes and i
When writing server-side code you need to explicitly stop execution after sending a Location:
I am getting Incorrect syntax near the keyword 'select' after executing the following code.
I have a curious problem in jQuery regarding order of execution. The code below
I am having problem to call onListItemClick() function after execution of onPostExecute(Void result) Below
In the below code, when I execute the producercon class, sometimes the execution stucks,
In the code below I want to call the method OpenNextPage through a call
I am running a piece of code that is throwing an error in eclipse.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.