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 2 of 2

Thread: GUI doesn't work when synchronized method is run

  1. #1
    Junior Member
    Join Date
    Jul 2011
    Posts
    13
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default GUI doesn't work when synchronized method is run

    Hi,

    I have an app with a main object (containing Swing GUI) and a supporting thread which calls on the handle() method of the object.

    I noticed that when the handle() method is synchronized, while the thread is using the handle() method, the GUI on the main object are unresponsive. Code:

    public synchronized void handle()){
    //method code
    }


    i remove the synchronized keyword from handle(), the GUI is responsive even when the thread is using the handle() method.

    An interesting thing to note is that when I used another object as a lock, the GUI becomes responsive again when the thread is using the handle() method. Code:

    public void handle(){
    synchronized(anotherObj){
    //method code
    }
    }

    This suggests that Swing GUI uses methods that are synchronized. Am I right? Feel free to point me to any resources - couldn't quite find what I wanted.

    Thanks.


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,462
    My Mood
    Hungover
    Thanks
    144
    Thanked 639 Times in 547 Posts

    Default Re: GUI doesn't work when synchronized method is run

    Without an SSCCE, I'm only guessing, but it sounds like you're locking up the Event Dispatching Thread (EDT). Don't do that.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. [SOLVED] cannot get this method to work properly
    By Nismoz3255 in forum Loops & Control Statements
    Replies: 2
    Last Post: May 2nd, 2011, 12:00 PM
  2. Synchronized block vs Synchronized method
    By tcstcs in forum Java Theory & Questions
    Replies: 1
    Last Post: April 20th, 2011, 07:51 AM
  3. Synchronized Collection
    By tcstcs in forum Java Theory & Questions
    Replies: 2
    Last Post: March 29th, 2011, 12:09 AM
  4. Synchronized Methods problem!
    By RiskyShenanigan in forum AWT / Java Swing
    Replies: 1
    Last Post: November 28th, 2010, 11:04 AM
  5. Replies: 3
    Last Post: April 18th, 2010, 10:08 AM