Results 1 to 12 of 12
  1. #1
    roadies07 is offline Member
    Join Date
    Jul 2010
    Posts
    9
    Rep Power
    0

    Smile No Difference In These Threads

    class A implements Runnable
    {
    public void run()
    {
    System.out.println(Thread.currentThread());
    //Thread.yield();
    System.out.println(Thread.currentThread());
    }
    }
    class Test
    {
    public static void main(String args[])
    {
    A a1=new A();
    A a2=new A();
    A a3=new A();
    Thread t1=new Thread(a1,"SINGO");
    Thread t2=new Thread(a2,"BINGO");
    t1.setPriority(2);t2.setPriority(7);
    t1.start();t2.start();
    }
    }

    why there is no difference in output after commenting the Thread.yield( )
    with Thread.yield( ) & Without Thread.yield( ) output is
    Thread[SINGO,2,main]
    Thread[BINGO,7,main]
    Thread[SINGO,2,main]
    Thread[BINGO,7,main]

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,883
    Rep Power
    25

    Default

    Why do you expect a difference?
    What happens if you sleep(1) vs yield()?
    What OS are you on?

    Here's what I get on WinXP
    Thread[BINGO,7,main]
    Thread[BINGO,7,main]
    Thread[SINGO,2,main]
    Thread[SINGO,2,main]

    0 error(s)

  3. #3
    roadies07 is offline Member
    Join Date
    Jul 2010
    Posts
    9
    Rep Power
    0

    Default

    Linux OS with Java 1.6

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,883
    Rep Power
    25

    Default

    What kind of task controls does it have? There are many different schemes for switching between competing tasks.

  5. #5
    roadies07 is offline Member
    Join Date
    Jul 2010
    Posts
    9
    Rep Power
    0

    Default

    Threads with high priorities should be executed first then the threads with low priorities.
    I think that concept is not fulfilled.

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,883
    Rep Power
    25

    Default

    If one thread yields what is the OS to do with other threads that are ready to execute?
    Must ALL of the highest priority tasks be completed before any lower priority ones can run?
    There are probably OSs that do that.
    Mine does, yours doesn't.

  7. #7
    roadies07 is offline Member
    Join Date
    Jul 2010
    Posts
    9
    Rep Power
    0

    Default

    as u r using Windows so u r getting answer totally different from me
    as i have mentioned u earlier that i don't get the output that u hav shown in the thread.
    m using Linux Os.

  8. #8
    roadies07 is offline Member
    Join Date
    Jul 2010
    Posts
    9
    Rep Power
    0

    Default

    and other thing u have mention
    "There are probably OS's that do that"
    do u think that Java program depends on operating system

  9. #9
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,883
    Rep Power
    25

    Default

    Utimately, yes.
    I've seen other thread related things operate differently on Linux vs Windows.

    We need some more experienced programmers to answer this one.

  10. #10
    roadies07 is offline Member
    Join Date
    Jul 2010
    Posts
    9
    Rep Power
    0

    Default

    In Which OS the Java will be at its Best ?

  11. #11
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,883
    Rep Power
    25

    Default

    Define Best.

  12. #12
    Singing Boyo is offline Senior Member
    Join Date
    Mar 2009
    Posts
    552
    Rep Power
    6

    Default

    Thread Priority = non-portable. Thats all I'll say on that one.

    Define Best.
    Best, in this context, is an attempt to describe something that does not exist. Java does not have an operating system it runs best on. It'd be more dependent on the actual computer itself, rather than the OS. Some OSs do some things better than others.
    If the above doesn't make sense to you, ignore it, but remember it - might be useful!
    And if you just randomly taught yourself to program, well... you're just like me!

Similar Threads

  1. what is the difference
    By ron87 in forum New To Java
    Replies: 5
    Last Post: 01-04-2011, 05:31 PM
  2. what is the difference between jsp and jsf?
    By makpandian in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 12-31-2008, 06:55 PM
  3. difference
    By nishant in forum New To Java
    Replies: 2
    Last Post: 09-17-2008, 07:04 PM
  4. Difference between ASP and JSP
    By barney in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 08-07-2007, 08:15 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
  •