title: Issue with sapjco3 driver
body: <p>I've written a Spring MVC (Spring framework 4.1.1) java 1.8 application that successfully connects to SAP using the sapjco3.jar driver, and I've accomplished this using the CustomDestinationDataProvider technique. I then use this drive to call RFCs in my SAP R/3 system. The java code is executed via api call from an AngularJS front end application.</p>
  
  <p>Something that I've discovered occuring about 5% of the time that the call to SAP happens is the following error occurs:</p>
  
  <pre><code>NestedServletException: Handler processing failed; nested exception is 
  java.lang.Error: java.lang.IllegalStateException: DestinationDataProvider 
  already registered 
  </code></pre>
  
  <p>Here's the contents of my CustomDestinationDataProvider.java file:</p>
  
  <pre><code>public class CustomDestinationDataProvider {
  
  public class MyDestinationDataProvider implements DestinationDataProvider {
      private DestinationDataEventListener eL;
      private HashMap&lt;String, Properties&gt; secureDBStorage = new HashMap&lt;String, Properties&gt;();
      public Properties getDestinationProperties(String destinationName) {
          try {
              Properties p = secureDBStorage.get(destinationName);
              if(p!=null) {
                  if(p.isEmpty())
                      throw new DataProviderException(DataProviderException.Reason.INVALID_CONFIGURATION, "destination configuration is incorrect", null);
                  return p;
              }
              return null;
          } catch(RuntimeException re) {
              throw new DataProviderException(DataProviderException.Reason.INTERNAL_ERROR, re);
          }
      }
      public void setDestinationDataEventListener(DestinationDataEventListener eventListener) {
          this.eL = eventListener;
      }
      public boolean supportsEvents() {
          return true;
      }
      public void changeProperties(String destName, Properties properties) {
          synchronized(secureDBStorage) {
              if(properties==null) {
                  if(secureDBStorage.remove(destName)!=null)
                      eL.deleted(destName);
              } else {
                  secureDBStorage.put(destName, properties);
                  eL.updated(destName); // create or updated
              }
          }
      }
  }
  
  public ArrayList&lt;MaterialBean&gt; executeAvailabilityCall(Properties connectProperties, String searchString) {
      String destName = "ABAP_AS";
      SAPDAO sapDAO = new SAPDAO(); 
      ArrayList&lt;MaterialBean&gt; searchResults = new ArrayList&lt;MaterialBean&gt;();
      MyDestinationDataProvider myProvider = new MyDestinationDataProvider();
      JCoDestination dest;
      try {
          com.sap.conn.jco.ext.Environment.registerDestinationDataProvider(myProvider);
      } catch(IllegalStateException providerAlreadyRegisteredException) {
      }
      myProvider.changeProperties(destName, connectProperties);
      try {
          dest = JCoDestinationManager.getDestination(destName);
          searchResults = sapDAO.searchAvailability(dest, searchString);
      } catch(JCoException e) {
          e.printStackTrace();
      } catch (Exception e) {
          e.printStackTrace();
      }
      myProvider.changeProperties(destName, null);
      try {
          com.sap.conn.jco.ext.Environment.unregisterDestinationDataProvider(myProvider);
      } catch(IllegalStateException providerAlreadyRegisteredException) {
          throw new Error(providerAlreadyRegisteredException);
      }
      return searchResults;
  }   // end method executeAvailabilityCall()
  }   // end class CustomDestinationProvider()
  </code></pre>
  
  <p>My guess is that multiple api calls are occuring at the same time, and once the first query registers the destination data provider, the subsequent queries, which try to also register the destination data provider, fail because they are using the same value for 'destName' in the executeAvailabilityCall method. </p>
  
  <p>Upon first glace, it seems to me like I should use a dynamic value for the destName variable instead of just using "ABAP_AS" for all queries. In other words, I should change the following line:</p>
  
  <pre><code>    String destName = "ABAP_AS";
  </code></pre>
  
  <p>to something like this:</p>
  
  <pre><code>    String destName = "ABAP_AS_" + LocalDateTime.now();
  </code></pre>
  
  <p>This would guarantee a unique value for the destName variable, thus a unique destination provider name. </p>
  
  <p>Any thoughts on the wisdom of trying this? If this is not a good idea, what other solution would be worth exploring?</p>