Results 1 to 5 of 5
  1. #1
    ASADUN is offline Member
    Join Date
    Dec 2009
    Posts
    2
    Rep Power
    0

    Smile Threads and Synchronization

    HI !

    I AM ASADUN, I HAVE STUDY THE BASIC OF JAVA LAST YEAR AND THIS YEAR I AM STUDYING JAVA ADVANCE BY MY SELF,I NEED YOUR HELP,COULD PLEASE EXPLAIN TO ME WITH SIMPLE WAY WHAT IS Threads and Synchronization, I REALLY TRIED TO READ MANY ARTICLES BUT STILL I DID NOT GET THE IDEA.

    THANK

    ASADUN
    Last edited by ASADUN; 12-03-2009 at 08:37 PM.

  2. #2
    CodesAway's Avatar
    CodesAway is offline Senior Member
    Join Date
    Sep 2009
    Location
    Texas
    Posts
    238
    Rep Power
    6

    Default

    Check out the Java tutorial on concurrency. It discusses threads and synchronization.


    Also, for future reference, please don't put your posts in caps. When writing on-line, capital letters are interpreted as yelling.
    CodesAway - codesaway.info
    writing tools that make writing code a little easier

  3. #3
    ASADUN is offline Member
    Join Date
    Dec 2009
    Posts
    2
    Rep Power
    0

    Default

    Hi !
    Here is a class calls "tuna" with three constructors in some constructors I see there is "this",and I cannot understand why we use it in this case
    Would like please explain to me what is the use for "this" in those constructors
    public class tuna {
    private int hour;
    private int minute;
    private int second;

    public tuna(){
    this(0,0,0);
    }

    public tuna(int h){
    this(h,0,0);
    }

    public tuna(int h, int m){
    this(h,m,0);
    }

    thanks

  4. #4
    CodesAway's Avatar
    CodesAway is offline Senior Member
    Join Date
    Sep 2009
    Location
    Texas
    Posts
    238
    Rep Power
    6

    Default

    Quote Originally Posted by ASADUN View Post
    Hi !
    Here is a class calls "tuna" with three constructors in some constructors I see there is "this",and I cannot understand why we use it in this case
    Would like please explain to me what is the use for "this" in those constructors
    public class tuna {
    private int hour;
    private int minute;
    private int second;

    public tuna(){
    this(0,0,0);
    }

    public tuna(int h){
    this(h,0,0);
    }

    public tuna(int h, int m){
    this(h,m,0);
    }

    thanks
    In the future, please create a separate topic for each distinct question. Only if your comment/question is in response to the topic should you reuse a topic.

    Now, as for your question. The "this" in your case is used to call another constructor in the class. So, in this case, all the constructors will be calling the three argument constructor (which is not in your example), but presumably would initialize the three fields to the the passed values.

    Since Java doesn't allow a parameter to have a default value, this methodology can be used to reproduce the same functionality. In this case, if you omit any of the hour/minute/second values, 0 will be used instead. Then, the constructor with three arguments (one for each hour, minute, and second) will be used to initialize the fields.
    CodesAway - codesaway.info
    writing tools that make writing code a little easier

  5. #5
    sebaksj123 is offline Member
    Join Date
    Dec 2009
    Posts
    1
    Rep Power
    0

Similar Threads

  1. Odd Even number synchronization in threads
    By DukeNukem in forum Threads and Synchronization
    Replies: 1
    Last Post: 03-16-2009, 02:02 PM
  2. Animation Synchronization
    By dreadrocksean in forum Advanced Java
    Replies: 5
    Last Post: 08-08-2008, 02:56 AM
  3. synchronization question
    By oguz in forum Threads and Synchronization
    Replies: 2
    Last Post: 07-22-2008, 08:56 AM
  4. Synchronization Doesn't seem to work
    By sherinpearl in forum Threads and Synchronization
    Replies: 1
    Last Post: 04-23-2008, 06:30 PM
  5. Synchronization problems
    By Jack in forum Advanced Java
    Replies: 2
    Last Post: 07-02-2007, 01:17 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •