Results 1 to 2 of 2

Thread: Thread question

  1. #1
    exernet is offline Member
    Join Date
    Dec 2009
    Posts
    2
    Rep Power
    0

    Default Thread question

    If someone could answer/explain this i'd greatly appreciate it.

    class MyClass{
    public synchronized void func1( ){

    }

    public synchronized void func2( ){

    }
    }

    MyClass myObj=new MyClass( ); // shared by both thread
    Thread 1

    myObj.func1( );
    Thread 2

    myObj.func2( );


    Do you think Thread 1 and Thread 2 can run myObj.func1() and myObj.func2() during the same time? Why or why not? Explain in detail.

  2. #2
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    What do you think? We are not simply going to do your homework for you. The key point is the "synchronized" keyword and it's location. What does "synchronized" do? What is being synchronized on?

Similar Threads

  1. Thread.sleep() and join() question
    By sandeepsai39 in forum New To Java
    Replies: 5
    Last Post: 04-20-2009, 06:51 AM
  2. an old question about Thread.Sleep()
    By narbeh in forum Threads and Synchronization
    Replies: 1
    Last Post: 03-25-2009, 07:12 AM
  3. Thread question
    By Moncleared in forum Advanced Java
    Replies: 5
    Last Post: 02-09-2009, 10:33 PM
  4. Thread.sleep() question
    By Lachezar in forum New To Java
    Replies: 5
    Last Post: 02-03-2009, 10:27 PM
  5. main thread question?
    By frejon26 in forum New To Java
    Replies: 1
    Last Post: 01-24-2008, 10:13 PM

Posting Permissions

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