简体   繁体   中英

Graphstream Multithreading - Java

I am relatively new to the threading world in Java and need some help please. I am using a deep recursion algorithm to build a graph, based on the Graphstream ( http://graphstream-project.org/ ) libray. However I encounter a Stackoverflow error. I am sure my algorithm is right (I tested on a small scale).

I read about threading and how this could help. My idea is to generate a new thread for each recursion (might go to millions :( ).. That would also generate a lot of sub graphs.. In the end, I would have to merge all those sub graphs in a single thread. Do you guys think that this would really help getting rid of the stackoverflow problem? Or do you have any other ideas for me!? Thanks!

Your idea is, in general, called MapReduce . Googling that should help you find a sample implementation.

Since your problem is a stack overflow error, remember, that you can rewrite each recursion to a looped algorithm which will not cause stack overflow errors.

Creating a lot of threads is usually a bad idea. Just use a ThreadPool or an Executor service.

Millions of threads is not an elegant way. Instead of threads, launch Runnables on an java.concurrent.Executor. This way you'll also get rid of Stackoverflow, and make the algorithm run in parallel on all available processors.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM