Solved

fork-join implimentation

Posted on 2012-03-14
4
238 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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to get all the API from website? 11 161
CSV file parsing thru Java 13 54
spring maven example issues 3 105
Netbeans and org.apache.commons.lang3 issue 3 55
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
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…
Suggested Courses

751 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