Solved

fork-join implimentation

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

867 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

18 Experts available now in Live!

Get 1:1 Help Now