itm/testbed-runtime — Issue #133: Two executors running exactly the same task
Author: massel
Created: 2012-01-19 16:38:26+00:00
State: open
Labels: Defect

Since we introduced the dynamic configurations we have two threads doing exactly the same thing:

IWSNFactoryImpl.java:

```java
final DOMObserver domObserver = domObserverFactory.create(newDOMProvider);

final IWSNOverlayManager overlayManager = overlayManagerFactory.create(
testbedRuntime,
domObserver,
nodeId
);

final IWSNApplicationManager applicationManager = applicationManagerFactory.create(
testbedRuntime,
domObserver,
nodeId
);

return new IWSNImpl(
testbedRuntime,
applicationManager,
overlayManager
);
```

--> overlayManager and applicationManager share one DOMObserver.

IWSNImpl.java:

```java
@Override
public void start() throws Exception {

log.info("Starting iWSN...");

log.debug("Starting overlay services...");
testbedRuntime.start();

log.debug("Starting overlay manager...");
overlayManager.start();

log.debug("Starting application manager...");
applicationManager.start();
```
During startup of TR both managers are started. Both start() methods of the managers do contain the same code:

```java
domObserverSchedule = scheduler.scheduleWithFixedDelay(domObserver, 0, 3, TimeUnit.SECONDS);
```

--> both threads run the run() method of the shared DOMObserver instance
----> we can save one thread and maybe gain some performance and less bugs due to race conditions :-)