Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: thread java

  1. #1
    Junior Member
    Join Date
    Feb 2014
    Location
    gurgaon
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default thread java

    Class A{
    Public static synchronized void main(String args[]){
    Thread t= new thread();
    t.start();
    Sysout("hi");
    t.wait(1000);
    Sysout("hello");
    }}


    Illegal state monitor exception. Why?


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,135
    My Mood
    Mellow
    Thanks
    187
    Thanked 659 Times in 646 Posts

    Default Re: thread java

    Welcome to the forum! Please read this topic to learn how to post code in code or highlight tags and other useful info for new members.

    Java is case sensitive. 'Public' is not the same as 'public'. Please post the entire error you're asking for help with, copied from exactly as it appears at your end.

  3. #3
    Junior Member
    Join Date
    Feb 2014
    Location
    gurgaon
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: thread java

     
    class A{
    public static synchronized void main(String args[]){
    Thread t= new Thread();
    t.start();
    System.out.println("hi");
    t.wait(1000);
    System.out.println("hello");
    }}
    o/p:
    hi
    Exception in thread "main" java.lang.IllegalMonitorStateException
    at java.lang.Object.wait(Native method)


    Works fine if we comment out wait statement
    Last edited by payalBansal; May 30th, 2014 at 04:03 AM.

  4. #4
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,135
    My Mood
    Mellow
    Thanks
    187
    Thanked 659 Times in 646 Posts

    Default Re: thread java

    Please post your code correctly as explained in the link I provided.

  5. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,427
    Thanks
    49
    Thanked 2,216 Times in 2,189 Posts

    Default Re: thread java

    Look up the API doc for the class: java.lang.IllegalMonitorStateException
    The reason for the exception is explained there.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. How to categorise a daemon thread to specific thread in java?
    By rajasekhar_b in forum What's Wrong With My Code?
    Replies: 0
    Last Post: January 10th, 2014, 06:55 AM
  2. Java New Thread KG
    By Courley4000 in forum Member Introductions
    Replies: 1
    Last Post: November 12th, 2013, 05:40 PM
  3. Replies: 1
    Last Post: September 24th, 2013, 04:18 PM
  4. Replies: 4
    Last Post: June 15th, 2012, 01:50 PM
  5. The Java 7 Thread
    By KevinWorkman in forum The Cafe
    Replies: 4
    Last Post: July 8th, 2011, 11:56 AM