2014-12-29 14 views
0

Я перешел от последовательных HTTP-вызовов к 4 службам REST, чтобы выполнить 4 одновременных вызова с использованием обычного менеджера задач рабочего менеджера. Я использую WebLogic 12c. Этот новый код работает в моей среде разработки, но в нашей тестовой среде в условиях загрузки, а иногда и не под нагрузкой, карта результатов не заполняется всеми результатами. Ведение журнала предполагает, что каждый рабочий элемент действительно получил результаты. Может ли это быть проблемой с ConcurrentHashMap? В этом примере из IBM они используют свою собственную версию Work и есть метод getData(), хотя это не нравится, что этот метод действительно существует в определении класса. Я выполнил другой пример, который просто использовал класс Work, но не продемонстрировал, как получить данные из этих потоков в основной поток. Должен ли я использовать execute() вместо schedule()? API не выглядит хорошо документированным. Время выдержки затвора достаточно велико. component.processInbound() на самом деле содержит код для HTTP-вызова, но я проблема не там, потому что я могу вернуться к синхронной версии класса ниже и не иметь никаких проблем.Использование диспетчера задач Commonj для отправки асинхронных HTTP-вызовов

http://publib.boulder.ibm.com/infocenter/wsdoc400/v6r0/index.jsp?topic=/com.ibm.websphere.iseries.doc/info/ae/asyncbns/concepts/casb_workmgr.html

Мой код:

public class WorkManagerAsyncLinkedComponentRouter implements 
     MessageDispatcher<Object, Object> { 

    private List<Component<Object, Object>> components; 
    protected ConcurrentHashMap<String, Object> workItemsResultsMap; 
    protected ConcurrentHashMap<String, Exception> componentExceptionsInThreads; 
... 

    //components is populated at this point with one component for each REST call to be made. 
    public Object route(final Object message) throws RouterException { 
    ... 
     try { 
      workItemsResultsMap = new ConcurrentHashMap<String, Object>(); 
      componentExceptionsInThreads = new ConcurrentHashMap<String, Exception>(); 
      final String parentThreadID = Thread.currentThread().getName(); 

      List<WorkItem> producerWorkItems = new ArrayList<WorkItem>(); 
      for (final Component<Object, Object> component : this.components) { 
       producerWorkItems.add(workManagerTaskExecutor.schedule(new Work() { 
        public void run() { 
         //ExecuteThread th = (ExecuteThread) Thread.currentThread(); 
         //th.setName(component.getName()); 
         LOG.info("Child thread " + Thread.currentThread().getName() +" Parent thread: " + parentThreadID + " Executing work item for: " + component.getName()); 
         try { 
          Object returnObj = component.processInbound(message); 
          if (returnObj == null) 
           LOG.info("Object returned to work item is null, not adding to producer components results map, for this producer: " 
             + component.getName()); 
          else { 
           LOG.info("Added producer component thread result for: " 
             + component.getName()); 
           workItemsResultsMap.put(component.getName(), returnObj); 
          } 
          LOG.info("Finished executing work item for: " + component.getName()); 
         } catch (Exception e) { 
          componentExceptionsInThreads.put(component.getName(), e); 
         } 
        } 
... 
       })); 
      } // end loop over producer components 

      // Block until all items are done 
      workManagerTaskExecutor.waitForAll(producerWorkItems, stuckThreadTimeout); 

      LOG.info("Finished waiting for all producer component threads."); 
      if (componentExceptionsInThreads != null 
        && componentExceptionsInThreads.size() > 0) { 
       ... 
      } 
      List<Object> resultsList = new ArrayList<Object>(workItemsResultsMap.values()); 
      if (resultsList.size() == 0) 
       throw new RouterException(
         "The producer thread results are all empty. The threads were likely not created. In testing this was observed when either 1)the system was almost out of memory (Perhaps the there is not enough memory to create a new thread for each producer, for this REST request), or 2)Timeouts were reached for all producers."); 
      //** The problem is identified here. The results in the ConcurrentHashMap aren't the number expected . 
      if (workItemsResultsMap.size() != this.components.size()) { 
       StringBuilder sb = new StringBuilder(); 
       for (String str : workItemsResultsMap.keySet()) { 
        sb.append(str + " "); 
       } 
       throw new RouterException(
         "Did not receive results from all threads within the thread timeout period. Only retrieved:" 
           + sb.toString()); 
      } 
      LOG.info("Returning " + String.valueOf(resultsList.size()) + " results."); 
      LOG.debug("List of returned feeds: " + String.valueOf(resultsList)); 
      return resultsList; 

     } 
... 
    } 
} 

ответ

0

Я кончался клонировать документ DOM используется в качестве параметра. Должен быть какой-то нисходящий код, который имеет побочные эффекты для параметра.