GraphStream Thread synchronization

335 Views Asked by At

I'am trying to create a tool for demonstrating graphs and algorithms. For that purpose I've found GraphStream library. I have read all of its documentation and tutorials but I cant make this one thing work. I am trying to put graph into my custom GUI (left menu with buttons and right graph space) and i managed to do that. Now when i enabled two buttons: generate - creates graph with random generator, and clear - clears graph, it all works fine but after clear when i press generate, i get following error:

Exception in thread "Thread-2" org.miv.pherd.IdAlreadyInUseException: a particle with the same identifier already exists (0)

I dont understand why this is a problem because in my simple test program without gui, i made simple code in main to do the same thing and it works:

public class Test {

public static void main(String[] args){

     Graph graph = new SingleGraph("test");

      graph.display();

      Generator generator = new BarabasiAlbertGenerator();
      generator.addSink(graph);
      generator.begin();
      for (int i = 0; i < 100; i++) {
      generator.nextEvents();
      }

      generator.end();

      graph.clear();
      generator = new BarabasiAlbertGenerator();
      generator.addSink(graph);
      generator.begin();
      for (int i = 0; i < 100; i++) {
      generator.nextEvents();
      }
      generator.end();


}

this code works but when i execute it within my GUI with buttons i throws error which I have mentioned above. I also checked how many threads are running in my program and it seems 3 of them are. I hope my problem is pretty clear and someone can help me. Thank you all!

1

There are 1 best solutions below

0
On BEST ANSWER

This is caused by a known bug in the BarabasiAlbertGenerator class (see the corresponding Graphstream users thread).

This bug is fixed in the 1.3.x versions of the libraries, which are currently available as the nightly builds at http://graphstream-project.org/pub/1.x/nightly-build/last/

(In future, this fix should be part of the regular Graphstream downloads)