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: Synchronized Methods problem!

  1. #1
    Junior Member
    Join Date
    Nov 2010
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Synchronized Methods problem!

    Hi,

    I have an assignment that needs to use synchronized methods, what I have to do is create a supermarket app in Java where I set a favourite item/product's ID and retrieve it however those two methods need to use synchronized methods. Also I am using a GUI, so how do I implement that into two buttons?

    e.g. Set Favourte, Retrieve Favourite?

       private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {                                         
     
        }                                        
     
        private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {                                         
     
        }   
     
     synchronized public void retrieveFav()throws InterruptedException {
     
        }
     
        synchronized public void setFav()throws InterruptedException {
     
        }
    Last edited by RiskyShenanigan; November 28th, 2010 at 05:52 AM.


  2. #2
    Super Moderator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,097
    Thanks
    169
    Thanked 779 Times in 725 Posts
    Blog Entries
    5

    Default Re: Synchronized Methods problem!

    See the following link: Using Synchronized Methods
    I presume you need to synchronize the method because of multithreading (you don't mention threads at all)? If so, be careful making calls to a Swing GUI - all processes unless otherwise noted in the API should be placed onto the swing event dispatch thread (see Swing and Threads

Similar Threads

  1. Completely Lost in this problem(multiple methods)
    By wacarter in forum What's Wrong With My Code?
    Replies: 0
    Last Post: March 31st, 2010, 04:44 PM
  2. methods help
    By hockey87 in forum AWT / Java Swing
    Replies: 1
    Last Post: March 9th, 2010, 10:57 PM
  3. Calling for methods
    By soccer_kid_6 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 28th, 2010, 11:13 PM
  4. Re-using methods?
    By Morevan in forum What's Wrong With My Code?
    Replies: 2
    Last Post: January 26th, 2010, 04:04 PM
  5. Working with Methods
    By duckman in forum Object Oriented Programming
    Replies: 3
    Last Post: November 9th, 2009, 07:27 PM