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...

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.

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.

aryan Sharma

Greenhorn

Posts: 27

posted 6 years ago

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....

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.