Results 1 to 3 of 3
  1. #1
    blf_titi is offline Member
    Join Date
    Jun 2010
    Posts
    4
    Rep Power
    0

    Default I need an idea with something really stupid

    Hi there.

    This might sound funny but I got a homework and I can`t make any sense of it.
    The statement sounds like this:
    "Find the 10 largest numbers in an array of 100.000 randomly generated integers. You will use threads to compare 2 numbers. A daemon thread will print at regular intervals the progress and the number of unchecked integers left."

    I know it`s not appropriate to ask for help on the forum regarding a homework but I am really REALLY frustrated .... I just can`t figure out why, and how, should I use threads to deal with number comparison .....

    Could you at least give me a starting idea on it ???

    Sorry for wasting your time.
    Last edited by blf_titi; 10-25-2010 at 10:04 PM.

  2. #2
    gmarut is offline Member
    Join Date
    Oct 2010
    Posts
    6
    Rep Power
    0

    Default

    It sounds like this problem could have been worded a little better. From what I am understanding, you are not actually using the thread itself to compare numbers, you are simply executing the bulk of the comparison algorithm inside a seperate thread. I would recommend you start here:

    Create a new thread object (which i will refer to as the 'comparison thread') which executes your block of code to run through and check all of the values in the array.

    Use your daemon thread to start the new comparison thread and then enter a "sleeping" loop to print out the status of what is going on from your comparison thread. Normally, I would not put the daemon thread to sleep (i would spawn yet another thread to do the reporting) but in this example, it shouldn't hurt.

    If you are not familiar with the two statements "volatile" (for variables) and "synchronized" (for methods), this would be a great time to read up on them. These two statements are used to ensure proper thread synchronization when working with multi-threading applications.

    If you have any further questions, I would be happy to help.

  3. #3
    blf_titi is offline Member
    Join Date
    Jun 2010
    Posts
    4
    Rep Power
    0

    Default

    Yes, I am familiar with volatile and synchronized so that shouldn`t be a problem. Anyway, thanks for the tip. At least now I have a pretty good starting point

Similar Threads

  1. Stupid error
    By dewitrydan in forum Java Applets
    Replies: 3
    Last Post: 08-09-2010, 02:29 PM
  2. incredibally stupid....
    By tek0011 in forum New To Java
    Replies: 7
    Last Post: 11-26-2009, 10:35 AM
  3. simple question feel stupid asking...
    By IYIaster in forum New To Java
    Replies: 3
    Last Post: 10-02-2009, 06:04 PM
  4. a really stupid question
    By SwinGirl in forum NetBeans
    Replies: 10
    Last Post: 06-25-2008, 10:06 PM
  5. Quick Stupid Question
    By bluekswing in forum New To Java
    Replies: 7
    Last Post: 01-08-2008, 07:35 PM

Tags for this Thread

Posting Permissions

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