0

I had a Java program that I run thousand times based on a loop (according to the number of files to be compiled to build a linux kernel) in a bash script.

There was a performance problem since the jvm was started several times...

What i've done then is implementing a wrapper in java that does the same as my bash script, reads one line from a file and then calls the main of my previous program... This way, I only have one jvm running...

The problem now is that only one core of my box is used which is another performance issue... Do I have to start some threads or can I use the same method but maybe calling the "former" main in a different way ? If i have to start some threads, how I dispatch them throughout the multiple cores ?

thanks...

4
  • Why do you use java to compile the kernel? I thought gcc has the ability of parallel compilation. If you don't have multiple cores there is only a slight chance you get performance benefit from multiple threads, as the compilation seems to be more CPU intensive than I/O intensive. IMHO. Commented Jun 25, 2009 at 19:16
  • 2
    FYI - you don't have to worry about dispatching threads to multiple cores. Just create the threads, and the OS will manage which cores they execute on. Commented Jun 25, 2009 at 19:16
  • if you're compiling something, why not just use GNU make? It has built-in support for parallelization. Commented Jun 25, 2009 at 19:16
  • no I'm not actually compiling things... At first, I had a wrapper around gcc to execute my program on what was compiled but then I realized that for each file, a new instance of the jvm was started ( so basically, you have concurrent execution but you're limited by starting jvm for each file...) Commented Jun 25, 2009 at 19:28

3 Answers 3

17

Your java program needs to become multi-threaded, in order to take advantage of many cores.

For example, create a thread pool using java.util.concurrent.Executors, encapsulate your data items as a Runnable, and submit the Runnable to the threadpool.

Sign up to request clarification or add additional context in comments.

Comments

3

At the risk of oversimplifying it, just have your old class implement Runnable, taking what was in main() and putting it in Run(), then create a new thread with that class and start the thread.

In reality it might be more complicated than that if the threads need to share data, but based on what you said you are doing here, it doesn't seem like they would. So it might actually be just that easy.

3 Comments

I've thought about that...but i don't know if it's oversimplified or not...that may be a good start...just to see if it works :-)
You should also do what skaffman said and use Executors and a ThreadPool (if you have Java 5 or later). You do not want 1000 threads running either.
I agree with Kathy - skaffman's answer should be what you're looking for.
1

You will need to make your program multi-threaded. You will have to do some learning to do this and I recommend you start with the Java Concurrency Tutorial.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.