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: Is it possible to acceessdifferent parts of class by different threads?

  1. #1
    Junior Member
    Join Date
    Nov 2012
    Thanked 1 Time in 1 Post

    Default Is it possible to acceessdifferent parts of class by different threads?

    Hi !my doubts are based on below programme.
    class C implements Runnable  
        public void f1()  
        public void run()  
        synchronized void f2()  
        class synchronized  
        public static void main (String args[])  
        C c1=new C();  
        Thread t1=new Thread(c1);  
        Thread t2=new Thread(c1);  
    Here c1 is object of class C.
    I have accessed method f1 of object c1 by threads t1 and t2.
    My Doubt:
    I want to access method f1 by thread t1 and f2 by thread t2.
    Is it possible?
    If possible please tell me

  2. #2
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    My Mood
    Thanked 263 Times in 232 Posts

    Default Re: Is it possible to acceessdifferent parts of class by different threads?

    Read several pages from here forward

    Post your new code and any questions you have. Most of what you ask is explained (or introduced at least) in about 4 pages.
    To answer your question, not as it is. Yes it is possible. Answer any questions you have left after you browse the tutorial past synchronized methods

Similar Threads

  1. Beginner having some trouble with two parts in my code
    By csprung in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 25th, 2012, 04:23 AM
  2. How do I parse an input file in two parts?
    By bryanboy in forum Java Theory & Questions
    Replies: 4
    Last Post: November 12th, 2011, 02:20 AM
  3. Hiding\Showing parts of the frame
    By liron50 in forum AWT / Java Swing
    Replies: 17
    Last Post: April 29th, 2011, 12:14 PM
  4. Repeating different parts of a program
    By swiftxjames in forum Loops & Control Statements
    Replies: 3
    Last Post: November 17th, 2010, 04:29 PM