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.


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
    Thanked 0 Times in 0 Posts

    Default Synchronized Methods problem!


    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 06:52 AM.

  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Thanked 833 Times in 772 Posts
    Blog Entries

    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, 11:57 PM
  3. Calling for methods
    By soccer_kid_6 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 1st, 2010, 12:13 AM
  4. Re-using methods?
    By Morevan in forum What's Wrong With My Code?
    Replies: 2
    Last Post: January 26th, 2010, 05:04 PM
  5. Working with Methods
    By duckman in forum Object Oriented Programming
    Replies: 3
    Last Post: November 9th, 2009, 08:27 PM