How to use power of Dual/ Quad core Processors in Applet?

Discussion in 'Java' started by Sanny, Jul 19, 2007.

  1. Sanny

    Sanny Guest

    I have a large Applet I wish to use Dual/ Quad core Computers to take
    advantage of all the 4/ 2 processors they have.

    Will the JVM automatically gives each thread devoted to one core or
    have to write something to assign different cores to different cores?

    Bye
    Sanny
    Sanny, Jul 19, 2007
    #1
    1. Advertising

  2. Sanny

    Patrick Guest

    Sanny a écrit :
    > I have a large Applet I wish to use Dual/ Quad core Computers to take
    > advantage of all the 4/ 2 processors they have.
    >
    > Will the JVM automatically gives each thread devoted to one core or
    > have to write something to assign different cores to different cores?


    If you write carefully your program with multiple threads, the JVM
    should assign them to different cores. But it may also depend of the
    operating system.

    --
    Patrick
    Patrick, Jul 19, 2007
    #2
    1. Advertising

  3. Sanny

    Twisted Guest

    On Jul 19, 7:31 am, Sanny <> wrote:
    > I have a large Applet I wish to use Dual/ Quad core Computers to take
    > advantage of all the 4/ 2 processors they have.
    >
    > Will the JVM automatically gives each thread devoted to one core or
    > have to write something to assign different cores to different cores?


    Just use threads to divide up the computational work in your
    application.
    Twisted, Jul 19, 2007
    #3
  4. Sanny

    Daniel Pitts Guest

    On Jul 19, 5:11 am, Patrick <> wrote:
    > Sanny a écrit :
    >
    > > I have a large Applet I wish to use Dual/ Quad core Computers to take
    > > advantage of all the 4/ 2 processors they have.

    >
    > > Will the JVM automatically gives each thread devoted to one core or
    > > have to write something to assign different cores to different cores?

    >
    > If you write carefully your program with multiple threads, the JVM
    > should assign them to different cores. But it may also depend of the
    > operating system.
    >
    > --
    > Patrick


    Actually, The threads themselves may not be "assigned" to specific
    cores, but when a core becomes free, the OS will choose which thread
    to schedule on that core. Although the actual algorithm is somewhat
    complicated, its fair to say that using multiple threads will give you
    a fairly even distribution among the cores, assuming you're using a
    modern OS and modern JVM.
    Daniel Pitts, Jul 19, 2007
    #4
  5. Sanny

    Sanny Guest

    > Actually, The threads themselves may not be "assigned" to specific
    > cores, but when a core becomes free, the OS will choose which thread
    > to schedule on that core. Although the actual algorithm is somewhat
    > complicated, its fair to say that using multiple threads will give you
    > a fairly even distribution among the cores, assuming you're using a
    > modern OS and modern JVM.


    Does Unix, Windows 98, Windows XP, Windows Vista, OS/2, Linux etc
    support Dual & Quad Processors.

    My Applet is for everyone. So I want it to work on every Operating
    System.

    One more Question does an Applet gets only those resources which
    Browser provides? Will it depend also on which browser the user is
    using.

    Is there a Chart where I can see which Browsers and Operating Systems
    support Dual Core/ Quad core Processoors.

    And Maximum how many threads can be created for an Applet. Can I
    create 100 or 1000 threads running Simultaniously without crashing the
    Browser?

    JAVA was once a very modern language but I feel it is loosing it's
    importance because of Microsoft Monopoly. Why do Microsoft not give
    enough support for Java. We see Flash works better than Applets and
    faster, While even little Applet takes lot of time to download. Why
    Browsers do not support Applet as par as Flash.

    Bye
    Sanny
    Sanny, Jul 20, 2007
    #5
  6. Sanny

    Roedy Green Guest

    >Will the JVM automatically gives each thread devoted to one core or
    >have to write something to assign different cores to different cores?


    So long as you have multiple threads, the multiple processors will be
    automatically exploited. The JVM does not assign a thread to a
    processor. On each slice the OS just gives the highest priority
    waiting thread to the first available processor.
    --
    Roedy Green Canadian Mind Products
    The Java Glossary
    http://mindprod.com
    Roedy Green, Jul 20, 2007
    #6
  7. Sanny

    Roedy Green Guest

    On Fri, 20 Jul 2007 00:51:15 -0700, Sanny <>
    wrote, quoted or indirectly quoted someone who said :

    >Is there a Chart where I can see which Browsers and Operating Systems
    >support Dual Core/ Quad core Processoors.


    You can find out with a simple benchmark than starts N threads to
    complete N chunks of compute intensive work. Compare that with the
    time to run 1 thread to do N chunks of compute intensive work.

    see http://mindprod.com/jgloss/benchmark.html
    --
    Roedy Green Canadian Mind Products
    The Java Glossary
    http://mindprod.com
    Roedy Green, Jul 20, 2007
    #7
  8. Sanny

    ~kurt Guest

    Sanny <> wrote:
    >
    > Does Unix, Windows 98, Windows XP, Windows Vista, OS/2, Linux etc
    > support Dual & Quad Processors.


    I know Solaris has supported multiple processors for a long time,
    same with Linux. I'm pretty sure Vista and XP do because I remember
    having support for dual processors even with NT.

    - Kurt
    ~kurt, Jul 21, 2007
    #8
  9. Sanny

    Roedy Green Guest

    On Sat, 21 Jul 2007 01:49:54 GMT, ~kurt <>
    wrote, quoted or indirectly quoted someone who said :

    >I'm pretty sure Vista and XP do because I remember
    >having support for dual processors even with NT.


    Duals have been supported since NT days, but I don't know about Quads.
    --
    Roedy Green Canadian Mind Products
    The Java Glossary
    http://mindprod.com
    Roedy Green, Jul 21, 2007
    #9
  10. Sanny

    pkriens Guest

    On Jul 20, 10:17 am, Roedy Green <>
    wrote:
    > >Will the JVM automatically gives each thread devoted to one core or
    > >have to write something to assign different cores to different cores?

    >
    > So long as you have multiple threads, the multiple processors will be
    > automatically exploited. The JVM does not assign a thread to a
    > processor. On each slice the OS just gives the highest priority
    > waiting thread to the first available processor.
    > --
    > Roedy Green Canadian Mind Products
    > The Java Glossaryhttp://mindprod.com

    Are you sure about this? Due to the problems with multi-core memory
    models I would expect a lot of Java code to fail due to lack of proper
    synchronization (which also handles memory synchronization between
    CPUs). I think some OSs have an affinity for a single CPU, at least I
    would not assign an application to multiple cores at the same time
    unless I was told the application could live in a multi-core world.

    Kind regards,

    Peter Kriens
    pkriens, Jul 21, 2007
    #10
  11. Sanny

    Guest

    On Jul 21, 6:20 am, pkriens <> wrote:
    > On Jul 20, 10:17 am, Roedy Green <>
    > wrote:> >Will the JVM automatically gives each thread devoted to one core or
    > > >have to write something to assign different cores to different cores?

    >
    > > So long as you have multiple threads, the multiple processors will be
    > > automatically exploited. The JVM does not assign a thread to a
    > > processor. On each slice the OS just gives the highest priority
    > > waiting thread to the first available processor.
    > > --
    > > Roedy Green Canadian Mind Products
    > > The Java Glossaryhttp://mindprod.com

    >
    > Are you sure about this? Due to the problems with multi-core memory
    > models I would expect a lot of Java code to fail due to lack of proper
    > synchronization (which also handles memory synchronization between
    > CPUs).


    Threaded code that doesn't synchronize properly will experience buggy
    behavior even on single-CPU systems. Threaded Java code that does
    synchronize properly should not experience buggy behavior on multi-CPU
    systems (at least, none that it can't also exhibit on single-CPU
    systems, i.e. buggy behavior that it can exhibit due to having bugs
    unrelated to race conditions, deadlocks, and other concurrency issues)
    and should naturally use the available cores subject to OS
    multiprocessing support and any OS affinity configuration. (Windows
    users can use task manager to force a running javaw.exe onto a single
    core or more generally a specific subset of the available cores, for
    example, but by default it will spread out to use them all, at least
    under the ubiquitous XP SP2.)

    Bug-free compute-intensive threaded Java code appears to function
    correctly and attain full CPU utilization on a dual-core Athlon with
    XP SP2 and Java 1.6.0_0something, in actual practise, also.
    , Jul 21, 2007
    #11
  12. Sanny

    Lew Guest

    Roedy Green wrote:
    >>> So long as you have multiple threads, the multiple processors will be
    >>> automatically exploited. The JVM does not assign a thread to a
    >>> processor. On each slice the OS just gives the highest priority
    >>> waiting thread to the first available processor.


    pkriens wrote:
    >> Are you sure about this? Due to the problems with multi-core memory
    >> models I would expect a lot of Java code to fail due to lack of proper
    >> synchronization (which also handles memory synchronization between
    >> CPUs).


    Of what "multi-core memory models" do you speak?

    Java has a well-defined memory model that the JVM on any system must follow.
    How is its memory model subject to "the problems with multi-core memory
    models"? (Be specific and precise.)

    Why would you expect "a lot of Java code to fail due to lack of proper
    synchronization" in greater proportion on multi-core systems than on
    single-core systems, given that both have to follow the Java Memory Model?

    Do you blame Java?

    wrote:
    > Threaded code that doesn't synchronize properly will experience buggy
    > behavior even on single-CPU systems. Threaded Java code that does
    > synchronize properly should not experience buggy behavior on multi-CPU
    > systems ... [more accurate and cogent information followed]


    Exactly. The memory model is the same. Concurrent programming is tricky. If
    pkriens were to actually study it, they might find that the Java Memory Model
    exists specifically to address issues that come up on multi-CPU systems but
    not on single-core systems.

    So whether Roedy is sure about his assertion or not, I sure am.

    --
    Lew
    Lew, Jul 21, 2007
    #12
  13. Roedy Green wrote:
    > On Sat, 21 Jul 2007 01:49:54 GMT, ~kurt <>
    > wrote, quoted or indirectly quoted someone who said :
    >> I'm pretty sure Vista and XP do because I remember
    >> having support for dual processors even with NT.

    >
    > Duals have been supported since NT days, but I don't know about Quads.


    Workstation is limited to 2.

    Server is limited to 4 and 8 depending on version (it is claimed
    that version with 32 exist, but ...).

    Arne
    =?ISO-8859-1?Q?Arne_Vajh=F8j?=, Jul 21, 2007
    #13
  14. Sanny wrote:
    >> Actually, The threads themselves may not be "assigned" to specific
    >> cores, but when a core becomes free, the OS will choose which thread
    >> to schedule on that core. Although the actual algorithm is somewhat
    >> complicated, its fair to say that using multiple threads will give you
    >> a fairly even distribution among the cores, assuming you're using a
    >> modern OS and modern JVM.

    >
    > Does Unix, Windows 98, Windows XP, Windows Vista, OS/2, Linux etc
    > support Dual & Quad Processors.


    Windows 98 does not. I am not sure of OS/2. The rest should.

    > My Applet is for everyone. So I want it to work on every Operating
    > System.


    Java shoudl enable you to do that.

    > One more Question does an Applet gets only those resources which
    > Browser provides? Will it depend also on which browser the user is
    > using.


    It should depend on th JVM used.

    > Is there a Chart where I can see which Browsers and Operating Systems
    > support Dual Core/ Quad core Processoors.


    You should read documentation for the OS's.

    > And Maximum how many threads can be created for an Applet. Can I
    > create 100 or 1000 threads running Simultaniously without crashing the
    > Browser?


    In theory yes. But all JVM's are not bug free.

    Note that 1000 threads will be painfully slow (unless it is a very
    huge system).

    > JAVA was once a very modern language but I feel it is loosing it's
    > importance because of Microsoft Monopoly. Why do Microsoft not give
    > enough support for Java. We see Flash works better than Applets and
    > faster, While even little Applet takes lot of time to download. Why
    > Browsers do not support Applet as par as Flash.


    Why did you expect MS to help the competition ??

    Arne
    =?ISO-8859-1?Q?Arne_Vajh=F8j?=, Jul 21, 2007
    #14
  15. Sanny

    ~kurt Guest

    Roedy Green <> wrote:
    >
    > Duals have been supported since NT days, but I don't know about Quads.


    One thing I could never figure out on that machine is, when I would run
    a process that sucked down a lot of CPU, and took a long time, it would
    hit both of the processors at 50%. I'd think a single process would
    hit the one processor at 100% (this was not a multi-threaded app). I'm
    wondering if the process manager would just indicate that both were being
    used to make me feel like I was getting my money's worth out of the machine.

    Around the same time, on our Solaris server, one process would max out
    one processor. We would fire up another process, and see the other
    processor fire up.

    - Kurt
    ~kurt, Jul 21, 2007
    #15
  16. Sanny

    Roedy Green Guest

    On Sat, 21 Jul 2007 03:20:49 -0700, pkriens <> wrote,
    quoted or indirectly quoted someone who said :

    >Are you sure about this? Due to the problems with multi-core memory
    >models I would expect a lot of Java code to fail due to lack of proper
    >synchronization (which also handles memory synchronization between
    >CPUs). I think some OSs have an affinity for a single CPU, at least I
    >would not assign an application to multiple cores at the same time
    >unless I was told the application could live in a multi-core world.


    You are saying the hardware is at fault -- it does not share memory
    between multi CPU caches as advertised? I know nothing about this. I
    am merely repeating a response given when someone a long time ago
    asked about how you lock a thread onto a CPU.

    A single CPU program will mask threading bugs longer than a dual CPU,
    so you should test multithreading code on a dual CPU.

    --
    Roedy Green Canadian Mind Products
    The Java Glossary
    http://mindprod.com
    Roedy Green, Jul 22, 2007
    #16
  17. Sanny

    Twisted Guest

    On Jul 21, 6:53 pm, ~kurt <> wrote:
    > Roedy Green <> wrote:
    >
    > > Duals have been supported since NT days, but I don't know about Quads.

    >
    > One thing I could never figure out on that machine is, when I would run
    > a process that sucked down a lot of CPU, and took a long time, it would
    > hit both of the processors at 50%. I'd think a single process would
    > hit the one processor at 100% (this was not a multi-threaded app). I'm
    > wondering if the process manager would just indicate that both were being
    > used to make me feel like I was getting my money's worth out of the machine.


    The Windows scheduler will sometimes move threads from one processor
    to another, so you can indeed have a single-threaded app using 50% of
    each of two cores. Set a processor affinity for this process using
    Task Manager and confine it to one core, and you'll see it run that
    core at 100% and leave the other idle.
    Twisted, Jul 22, 2007
    #17
  18. pkriens wrote:
    > On Jul 20, 10:17 am, Roedy Green <>
    > wrote:
    >>> Will the JVM automatically gives each thread devoted to one core or
    >>> have to write something to assign different cores to different cores?

    >> So long as you have multiple threads, the multiple processors will be
    >> automatically exploited. The JVM does not assign a thread to a
    >> processor. On each slice the OS just gives the highest priority
    >> waiting thread to the first available processor.

    > Are you sure about this? Due to the problems with multi-core memory
    > models I would expect a lot of Java code to fail due to lack of proper
    > synchronization (which also handles memory synchronization between
    > CPUs). I think some OSs have an affinity for a single CPU, at least I
    > would not assign an application to multiple cores at the same time
    > unless I was told the application could live in a multi-core world.


    Assuming that:
    - the Java program is written correctly according to Java memory model
    - the JVM is implemented correctly
    then it will work.

    Multi CPU or core context is just more likely to see buggy code
    actual fail. But the code is not less buggy on a single CPU and core
    system and it could also fail there - it may just be one out
    of a million instead of one out of two chance.

    Arne
    =?ISO-8859-1?Q?Arne_Vajh=F8j?=, Jul 22, 2007
    #18
  19. Sanny

    ~kurt Guest

    Twisted <> wrote:
    >
    > each of two cores. Set a processor affinity for this process using
    > Task Manager and confine it to one core, and you'll see it run that
    > core at 100% and leave the other idle.


    Ah. Although, I generally try not to mess with these things. My assumption
    is the people who design the kernel know a lot more about how to split up
    resources than I do....

    - Kurt
    ~kurt, Jul 22, 2007
    #19
  20. Sanny

    pkriens Guest

    On Jul 22, 1:17 am, Roedy Green <>
    wrote:
    > On Sat, 21 Jul 2007 03:20:49 -0700, pkriens <> wrote,
    > quoted or indirectly quoted someone who said :
    >
    > >Are you sure about this? Due to the problems with multi-core memory
    > >models I would expect a lot of Java code to fail due to lack of proper
    > >synchronization (which also handles memory synchronization between
    > >CPUs). I think some OSs have an affinity for a single CPU, at least I
    > >would not assign an application to multiple cores at the same time
    > >unless I was told the application could live in a multi-core world.

    >
    > You are saying the hardware is at fault -- it does not share memory
    > between multi CPU caches as advertised? I know nothing about this. I
    > am merely repeating a response given when someone a long time ago
    > asked about how you lock a thread onto a CPU.
    >
    > A single CPU program will mask threading bugs longer than a dual CPU,
    > so you should test multithreading code on a dual CPU.
    >
    > --
    > Roedy Green Canadian Mind Products
    > The Java Glossaryhttp://mindprod.com


    The Java memory model allows the caches of the processors to differ
    for variables that are not synchronized or volatile. So on processor A
    you can read a different value for variable x than on processor B
    until they are synchronized. Code that works well on a single
    processor because there is only one memory can fail subtly on multiple
    processors. Obviously the code is wrong, but I think it makes sense to
    schedule Java programs on a single CPU unless specifically allowed.

    Kind regards,

    Peter Kriens
    pkriens, Jul 23, 2007
    #20
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Simon Wittber

    Help me use my Dual Core CPU!

    Simon Wittber, Sep 12, 2006, in forum: Python
    Replies:
    23
    Views:
    752
    mystilleef
    Sep 18, 2006
  2. Tim Golden

    RE: Help me use my Dual Core CPU!

    Tim Golden, Sep 12, 2006, in forum: Python
    Replies:
    13
    Views:
    523
    Michael
    Oct 1, 2006
  3. Sanny
    Replies:
    2
    Views:
    1,009
    Roedy Green
    Jan 10, 2008
  4. Sanny
    Replies:
    4
    Views:
    430
    Mark Space
    Feb 3, 2008
  5. Malcolm Greene
    Replies:
    1
    Views:
    642
    Paul Rubin
    Apr 7, 2008
Loading...

Share This Page