Solved

fork-join implimentation

Posted on 2012-03-14
4
236 Views
Last Modified: 2012-08-13
hi guys

I have some executor service code which i want to re-write using fork-join. I am looking for better scalability.

ExecutorService executor = Executors.newFixedThreadPool(3);                        
 final HSSFWorkbook runnableWb = wb;
 Runnable expTask = new Runnable(){        
 public void run(){        
 getExportDocumentObject(true, "Excel",buffer, mReq,runnableWb);
 }
executor.submit(expTask);
shutdownAndAwaitTermination(executor);

How do i rewrite the above code snippet using fork join API?

thanks
0
Comment
Question by:royjayd
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 

Author Comment

by:royjayd
ID: 37763920
fork-join is a new feature provided in java 7 if i am not mistaken. If anyone has worked with it i would greatly appreciate any help.
0
 
LVL 35

Expert Comment

by:mccarl
ID: 37763943
As explained in this Java Tutorial, the actual code that does the work needs to be explicitly coded to work with the Fork/Join API. It's not something where you can just submit your method that does the work to a different API and you somehow magically get better scalability, multithreaded code. You need to actually think about your problem and what the code (within that getExportDocumentObject method) is doing and work out a) if there are benefits of doing multi-threading and if so, b) actually changing that code to do be able to be run in a multi-threaded way.

As I asked in another of your questions on this stuff, what is actually happening within that method, eg. database access, filesystem acces, CPU intensive algorithms, etc? Also, you claim that you are after better scalability; what have you done to determine that the current situation is not good enough? As I also said in a different question, the app server will already be servicing your requests in a multi-threaded way, and so it is likely that you will already have a reasonably scalable solution already.
0
 

Author Comment

by:royjayd
ID: 37764030
>>>As I asked in another of your questions on this stuff, what is actually happening within that method
well, the code i posted is just an example. It could be any code. I want to learn how to use fork-join implimentation and the benefits of using it.
0
 
LVL 35

Accepted Solution

by:
mccarl earned 405 total points
ID: 37764071
>>> well, the code i posted is just an example.

But, in your original question you said...

>>> How do i rewrite the above code snippet using fork join API?

Hence, why I was specifically responding with regards to the above code! Anyway, if as you say, "it could be any code", then the link that I posted provides a good example using "any code". The benefits of it, is that it is just one other way of implementing multi-threaded code, and one that works particularly well with a specific set of problems, ie. problems that can be broken down into smaller units and performed recursively.

I think the link I posted explains it fairly weel, so if you are still after more understanding of the fork-join stuff, are you possibly able to state more specifically what you need more help with?
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
The viewer will learn how to implement Singleton Design Pattern in Java.

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question