Results 1 to 2 of 2
  1. #1
    exernet is offline Member
    Join Date
    Dec 2009
    Rep Power

    Default Couple of questions regarding threading

    Teacher posted some review questions and I'm not to sure on these 2. If someone could explain the answers i'd greatly appreciate it.

    1) Given a Runnable-derived class: MyTask, please use an ExecutorService object to create three threads, each of which runs MyTask. Assume the constructor of MyTask is default, requiring no arguments.


    2) Here is a simple class:

    class MyClass{
    public synchronized void func1( ){


    public synchronized void func2( ){


    MyClass myObject=new MyClas( ); // 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.fun2() during the same time? Why or why not? Explain in detail.

  2. #2
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Rep Power


    Typical exam trick question. No, thread1 and thread2 cannot do that as the code won't compile. myObj is never initialized.
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

Similar Threads

  1. A couple of problems trying to get solved
    By nick2price in forum New To Java
    Replies: 3
    Last Post: 01-18-2009, 09:21 PM
  2. Couple of newbie questions
    By ananasman in forum New To Java
    Replies: 11
    Last Post: 11-20-2008, 11:54 PM
  3. Replies: 9
    Last Post: 10-18-2008, 04:31 PM
  4. Java assignment - couple methods don't know how to figure out
    By Snowboardmylife in forum New To Java
    Replies: 1
    Last Post: 04-16-2008, 10:52 AM
  5. Couple of Problems
    By joz_12345 in forum Java 2D
    Replies: 2
    Last Post: 03-06-2008, 04: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