# Executing Graph multiple times

**URL:** <https://forum.cloverdx.com/t/executing-graph-multiple-times/722>\
**Category:** CloverDX Platform\
**Created:** [June 17, 2010, 12:00am UTC](https://forum.cloverdx.com/t/executing-graph-multiple-times/722 "2010-06-17T00:00:00Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![gribr](https://avatars.discourse-cdn.com/v4/letter/g/df705f/32.png) [@gribr](https://forum.cloverdx.com/u/gribr)\
**Post date:** [June 17, 2010, 12:00am UTC](https://forum.cloverdx.com/t/executing-graph-multiple-times/722/1 "2010-06-17T00:00:00Z")

</div>

Hi,

I’ve followed the guibe to embedding Clover (2.9.3) [http://wiki.cloveretl.com/doku.php?id=embedding\_clover](http://wiki.cloveretl.com/doku.php?id=embedding%5Fclover) but am having problems executing my graph multiple times. It will execute fine the 1st time but it goes into a loop the second time. I have tried using both

```auto

  //graph loading
  TransformationGraph graph = TransformationGraphXMLReaderWriter.loadGraph(in, runtimeContext.getAdditionalProperties());

  //engine initialization
  EngineInitializer.initGraph(graph, runtimeContext);

  IThreadManager threadManager = new SimpleThreadManager();
  WatchDog watchDog = new WatchDog(graph, runtimeContext);
  threadManager.executeWatchDog(watchDog);

  sleep(5000);

  threadManager.executeWatchDog(watchDog);

```

and

```auto

  //graph loading
  TransformationGraph graph = TransformationGraphXMLReaderWriter.loadGraph(in, runtimeContext.getAdditionalProperties());

  //engine initialization
  EngineInitializer.initGraph(graph, runtimeContext);

  runGraph.executeGraph(graph, runtimeContext);

  sleep(5000);

  runGraph.executeGraph(graph, runtimeContext);

```

This is what is in the logs continually on the second execution:

> DEBUG [WatchDog] - incoming msg:null  
> INFO [WatchDog] - ---------------------\*\* Start of tracking Log for phase [0] \*\*-------------------  
> INFO [WatchDog] - Time: 17/06/10 12:23:44  
> INFO [WatchDog] - Node Status Port #Records #KB Rec/s KB/s  
> INFO [WatchDog] - ---------------------------------------------------------------------------------  
> INFO [WatchDog] - DATA\_READER2 RUNNING  
> INFO [WatchDog] - %cpu:… Out:0 3 1 0 0  
> INFO [WatchDog] - MYSQL\_DATA\_WRITER0 FINISHED\_OK  
> INFO [WatchDog] - %cpu:… In:0 3 2 0 0  
> INFO [WatchDog] - REFORMAT0 RUNNING  
> INFO [WatchDog] - %cpu:… In:0 3 1 0 0  
> INFO [WatchDog] - Out:0 3 2 0 0  
> INFO [WatchDog] - ---------------------------------\*\* End of Log \*\*--------------------------------

any ideas?  
Cheers.

---

<div class="post-metadata">

**Author:** ![avackova](https://avatars.discourse-cdn.com/v4/letter/a/65b543/32.png) [@avackova](https://forum.cloverdx.com/u/avackova)\
**Post date:** [June 17, 2010, 1:17pm UTC](https://forum.cloverdx.com/t/executing-graph-multiple-times/722/2 "2010-06-17T13:17:45Z")

</div>

Hello,  
you have to call graph.reset() method between particular graph execution:

```auto
			
graph = TransformationGraphXMLReaderWriter.loadGraph(new FileInputStream(file), runtimeContext.getAdditionalProperties());
EngineInitializer.initGraph(graph, runtimeContext);
IThreadManager threadManager = new SimpleThreadManager();
WatchDog watchDog = new WatchDog(graph, runtimeContext);
futureResult = threadManager.executeWatchDog(watchDog);
Result result = futureResult.get();
graph.reset();
futureResult = threadManager.executeWatchDog(watchDog);
result = futureResult.get();
graph.free();

```

---

<div class="post-metadata">

**Author:** ![gribr](https://avatars.discourse-cdn.com/v4/letter/g/df705f/32.png) [@gribr](https://forum.cloverdx.com/u/gribr)\
**Post date:** [June 23, 2010, 11:42am UTC](https://forum.cloverdx.com/t/executing-graph-multiple-times/722/3 "2010-06-23T11:42:15Z")

</div>

Yes I tried that but it still goes into a loop when the 2nd threadManager.executeWatchDog(watchDog); is called. This also happens when I tried your example.  
The only way I could get it to work was to add a sufficient sleep time between executeGraph() calls.

```auto

Future<Result> result = runGraph.executeGraph(graph, runtimeContext);
sleep(5000);
graph.reset();
result = runGraph.executeGraph(graph, runtimeContext);

```

Adding the sleep() using the threadManager method did not work, it still looped.

---

<div class="post-metadata">

**Author:** ![mzatopek](https://avatars.discourse-cdn.com/v4/letter/m/b5e925/32.png) [@mzatopek](https://forum.cloverdx.com/u/mzatopek)\
**Post date:** [June 28, 2010, 8:42am UTC](https://forum.cloverdx.com/t/executing-graph-multiple-times/722/4 "2010-06-28T08:42:19Z")

</div>

I have updated the related wiki page

[http://wiki.cloveretl.com/doku.php?id=embedding\_clover#embedding\_clover](http://wiki.cloveretl.com/doku.php?id=embedding%5Fclover#embedding%5Fclover)

Please follow the example, I hope it helps.

In short:

1. you don’t need to ‘reset’ the graph anymore
2. you need to create a watchdog instance for each separete graph run

Let me know if the example on wiki page is not comprehensive. More detailed piece of code is also available at our junit test org.jetel.graph.ResetTest.

---

<div class="post-metadata">

**Author:** ![mzatopek](https://avatars.discourse-cdn.com/v4/letter/m/b5e925/32.png) [@mzatopek](https://forum.cloverdx.com/u/mzatopek)\
**Post date:** [June 28, 2010, 8:46am UTC](https://forum.cloverdx.com/t/executing-graph-multiple-times/722/5 "2010-06-28T08:46:52Z")

</div>

All mentioned above is totally right from release 3.0 which is not still public 🙂 But you can download it from our svn trunk, it should be already pretty stable. We are going to release it in few days.

For older clover release I still recommend to be inspired by org.jetel.graph.ResetTest junit test (should be part of each source distribution).

Let me know if you don’t have it. Martin
