Solved

fork-join implimentation

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…

708 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now