From the middle of last year, began to learn Java, mainly to maintain the company's Java-written server software. At present, the server software encountered a problem, when downloading large files, if you download a lot of users at the same time, the server software work will be abnormal, some users can not download. Server hardware is mostly multi-core, so using OpenMP in the Java language can improve the performance of your server software.
Today, we tested it, and OpenMP is also available in the Java language. The following is a detailed test procedure:
1. Download Jomp1.0b.jar
Https://www2.epcc.ed.ac.uk/computing/research_activities/jomp/download/jomp1.0b.jar
2. Deploy Jomp1.0b.jar to the JDK's lib and append to Classpath.
It can also be used as an application class without appending to the system variable, but directly decompressing it.
3. Write the test code TESTJAVAOPENMP.JOMP. The extension must be jomp.
Import java.util.*;
public class Testjavaopenmp
{
public static void Main (string[] agrs)
{
int i;
//omp Parallel for
for (i = 0; i <; i++)
{
System.out.println ("i =" + i);
}
}
}
4. Generate Java files from Jomp:
Java Jomp.compiler.Jomp testjavaopenmp. (This is not with the jomp extension)
Generates a Testjavaopenmp.java file.
5. Compile Testjavaopenmp.java:
Javac Testjavaopenmp.java. Generate Testjavaopenmp.class File
6. Run:
java-djomp.threads=2 TESTJAVAOPENMP
A running result:
i = 0
i = 10
i = 1
i = 2
i = 11
i = 12
i = 3
i = 13
i = 14
i = 4
i = 15
i = 5
i = 16
i = 6
i = 17
i = 7
i = 18
i = 8
i = 9
i = 19
Java-djomp.threads=4 TESTJAVAOPENMP
A running result:
i = 15
i = 0
i = 10
i = 5
i = 11
i = 1
i = 16
i = 2
i = 12
i = 6
i = 13
i = 14
i = 3
i = 17
i = 18
i = 19
i = 4
i = 7
i = 8
i = 9
As you can see, the results are similar to the results in the C + + language. Whether it really runs on multicore requires a comparison of elapsed time to know.
Reference pages:
Https://www2.epcc.ed.ac.uk/computing/research_activities/jomp/download.html
Using OpenMP in the Java language