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

Thread: Fixing of bug for a small program

  1. #1
    Member
    Join Date
    Mar 2009
    Posts
    48
    Thanks
    3
    Thanked 2 Times in 2 Posts

    Default Fixing of bug for a small program

    Hallo I fount this code but I think is not right. Could you repair this code. What is missing?
    class Save {
      private int value;
      public sychronized void setValue(int i) {
        this.value = i;
      }
     
      public sychronized Object getValue() {
        return this.value;
      }
    }
     
    class ThreadOne {
      private Save save;
     
      run() {
        ...
        save.setValue(x);
     
      }  
    }
     
    class ThreadTwo {
      private Save save;
     
      run() {
        ...
        Sysout(save.getValue())
     
      }  
    }
     
    Save save = new Save();
     
    ThreadOne one = new ThreadOne();
    one.setSave(save);
     
    ThreadTwo two = new ThreadTwo();
    two.setSave(save);
     
    one.start();
    two.start();
    Thank you


  2. #2

    Default Re: Threads and variable

    Hi Koren,

    Can you provide more info about your problem please? What do you want to do?

  3. #3
    Member
    Join Date
    Mar 2009
    Posts
    48
    Thanks
    3
    Thanked 2 Times in 2 Posts

    Default Re: Threads and variable

    Hi Leandro,
    I solved this stuff. This is normal getter and setter...

  4. #4

    Default Re: Threads and variable

    Great. Good luck

Similar Threads

  1. Java Variable Conversions
    By JavaPF in forum Java Programming Tutorials
    Replies: 2
    Last Post: June 23rd, 2009, 05:03 AM
  2. Replies: 24
    Last Post: April 14th, 2009, 03:43 PM
  3. [SOLVED] Problem while getting a number from another thread
    By Koren3 in forum Threads
    Replies: 4
    Last Post: April 7th, 2009, 01:42 PM
  4. How to do thread communication in java
    By Koren3 in forum Threads
    Replies: 4
    Last Post: March 29th, 2009, 10:49 AM