Showing posts with label java 8. Show all posts
Showing posts with label java 8. Show all posts

Monday, April 21, 2014

Concurrency, Parallelism, Multicore

There were considerate amount of updates to Java language, JDK & JVM in the recent release of 1.8. It was said that finally Java is addressing multi-core hugely in Java 8. So I got excited about multicore, concurrency, parallelism etc. Here I'm not going to talk about evolution of multicore or Moore's Law blah blah blah. I'm going to talk about what I learnt about concurrency & parallelism, especially in Java (may be about Go in future).

As Rob Pike said Concurrency is not Parallelism. Concurrency is about dealing with lot of things at ones whereas Parallelism is about doing lot of things at ones. Concurrency is to structure things so that we may use parallelism to do a better job. Parallelism is not the goal of Concurrency. Concurrency's goal is good structure. Parallelism can come from better concurrent expression of the problem. The parallelism performance by an application achieved varies with different hardware configurations, depending on number of cores, number of threads per core etc. But if we have a proper concurrent design we can get Parallelism whenever possible.

There are different types of approaches to concurrency, to name a few:

1) Memory Sharing - Java
2) Message Passing - Erlang, Go

There are different debates about different types of approaches. As of now there is no barometer to validate which one is better. We may measure & compare performances of different approaches though. Depending on the approach different languages uses different terminology, the rest of my discussion is more related to Java world. Though the final goal of any approach, given any programming language, is to take advantage of all the cores available on the processor to increase the performance of applications.

The number of cores on the processors are increasing year after year. Rather than waiting for the CPU clock speeds to increase, software applications should be fine tuned in order to use all the cores on the processor. Concurrency should be addressed at the design stage of the application. Each core usually has one thread (more than one in some cases like HyperThreading). The ultimate goal is to keep all the threads (in different cores) running at any given time. 

There are lot of issues that need to be dealt while creating multi-threaded applications like thread creation, thread life cycle management, scheduling etc. Luckily many programming languages provide us with necessary language features, frameworks in dealing with them. Multi-threaded applications should be designed very carefully because when different threads try to communicate it could lead to issues like dead locks, starvation etc. Each approach addresses them in respective ways. From the next post I will dive deep into concurrency in Java. How Java & JDK is evolved overtime to address concurrency, starting from Java 1.0 till Java 8.

Sunday, April 6, 2014

Configuring Java Environment JRE/ JDK in Eclipse

Devoid of what version of JDK you install on your machine, Eclipse comes with a JDK and it uses it unless we configure it manually to use a different one. We can simply direct Eclipse by specifying -vm option in the  eclipse.ini file which you can find in the directory where you unzip the downloaded eclipse zip file. There are different ways of specifying the -vm option depending on the operating system, which are described in detail here. The following worked for me on windows. Specify the option at the top of the file.

-vm
C:/Program Files (x86)/Java/jdk1.7.0_51/jre/bin/client/jvm.dll

Alternately we can install different versions of JREs on Eclipse manually as follow:
Click Eclipse menu named Window -> select menu option Preferences, the following window pops up.



Select Java from the left panel and click on Installed JREs. We can select one the JREs by checking the checkbox, add more versions of JREs which are available for selection while creating a new project.

Different versions of Eclipse support different versions of Java Development. In order to find out which versions of Java does an Eclipse version supports. Click the Compiler from the left panel from the above window. We can see a drop down list with all Java versions that Eclipse version supports. 


We may have to update or install patches in order to make Eclipse support later versions of Java Development. For example, Eclipse Kepler supports Java 7 by default, if we need Java 8 support in Kepler, we have to install this patch.

In certain scenarios, we may want to change an existing  project to a different version of Java. We may do that as follows:

Right click on the Project from Project Explorer, Click Properties, the following window pops up. Click Java Compiler from the left panel. There we can change the Compiler Compliance Level. We may have to build the project when ever we change the JDK/ JRE.


Next in order the update the JRE/ JDK associated with the project, we have to manually edit it from the project BuildPath as follows:
Right Click on Project from the Package Explorer, select BuildPath, then select Configure BuildPath from the sub menu. The following Properties window pops up. 


Select Libraries tab. You should see a version of JRE System Library. Select that and click Remove and then click on Add Library. The following window pops up. Select JRE System Library.


You will have 3 options to select the desired JRE library. Select a JRE/ JDK and click Finish. You should see the relevant JRE/ JDK added to your project BuildPath.

  

Fork me on GitHub