*
The moose likes Threads and Synchronization and the fly likes how can programmers ensure appropriate usage of multiple processors while writing multi threaded cod Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "how can programmers ensure appropriate usage of multiple processors while writing multi threaded cod" Watch "how can programmers ensure appropriate usage of multiple processors while writing multi threaded cod" New topic
Author

how can programmers ensure appropriate usage of multiple processors while writing multi threaded cod

aryan Sharma
Greenhorn

Joined: Oct 10, 2005
Posts: 27
someone asked me if there's anything particular a java programmer should keep in mind while writing concurrent softwares those are deployed on machines with multiple cores , to ensure ideal usage of those multi-processors... my own sense is there's nothing special to be kept in mind by the programmer as the proper usage of the these multiple cores would be taken care by the JVM and deployment time JVM params...

guys let me know your thoughts....
Nitesh Kant
Bartender

Joined: Feb 25, 2007
Posts: 1638

Although this is a very vague question, there are a few things that one should actually take care.

1) Any OS or threading library can not speed up a poorly written code. eg: if you have a piece of code that is invoked by every request in a web application and you take a class level lock before executing that code. Your application can never really have a great throughput. This will not make much of a difference on a single processor box but your scalability will be close to zero by adding more processors.

2) Since multiple core (or hyper-threaded) boxes are capable of running multiple threads in parallel so an application should be aware of that when choosing the number of threads that run for that application. One can divide the code in such a way that CPU bound tasks are in a different pool than the IO bound tasks so that they can be scaled/configured differently. Of course, there is a penalty of context switches but one needs to be aware of such things before making an architectural decision.

There are a lot of things that goes into scalability with additional processing power which a programmer should be aware of. Its not really as simple as it sounds.


apigee, a better way to API!
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41046
    
  43
Of course, the JVM can only schedule threads to run on multiple cores in parallel if there *are* multiple threads. For a web app, this happens automatically through request-level parallelism (each of which has their own thread), but for other problems (like number crunching) the developer must create multiple threads, and ensure that those have as little interaction with other threads as possible. Implementing efficient parallel algorithms is hard.


Ping & DNS - my free Android networking tools app
aryan Sharma
Greenhorn

Joined: Oct 10, 2005
Posts: 27
Nitesh Kant wrote:
There are a lot of things that goes into scalability with additional processing power which a programmer should be aware of. Its not really as simple as it sounds.


This is what i want to know. is there any technical literature you can point to which suggests certain design guidelines....
Nitesh Kant
Bartender

Joined: Feb 25, 2007
Posts: 1638

aryan Sharma wrote:This is what i want to know. is there any technical literature you can point to which suggests certain design guidelines....


Well there is no holy grail for scalability. Everybody does it differently based on the kind of environment/architecture they have. You can read tons of articles on high scalability on what works for people.
 
Consider Paul's rocket mass heater.
 
subject: how can programmers ensure appropriate usage of multiple processors while writing multi threaded cod
 
Similar Threads
Threads running on single-core or multi-core?
Multi-Core Vs. Single-Core (For the serious Java Archs)
Dr Dobbs on functional languages
Oh my gawd, Java is doomed
What is Multi-Core Complexity