Project

General

Profile

« Previous | Next » 

Revision 10104

Added by Jing Tao over 7 years ago

Don't share the same executor in the two classes.

View differences:

src/edu/ucsb/nceas/metacat/dataone/MNodeService.java
52 52
import java.util.Timer;
53 53
import java.util.UUID;
54 54
import java.util.Vector;
55
import java.util.concurrent.ExecutorService;
56
import java.util.concurrent.Executors;
55 57

  
56 58
import javax.servlet.http.HttpServletRequest;
57 59
import javax.xml.transform.Result;
......
154 156
import edu.ucsb.nceas.metacat.index.MetacatSolrEngineDescriptionHandler;
155 157
import edu.ucsb.nceas.metacat.index.MetacatSolrIndex;
156 158
import edu.ucsb.nceas.metacat.properties.PropertyService;
157
import edu.ucsb.nceas.metacat.restservice.v2.MNResourceHandler;
158 159
import edu.ucsb.nceas.metacat.shared.MetacatUtilException;
159 160
import edu.ucsb.nceas.metacat.util.DeleteOnCloseFileInputStream;
160 161
import edu.ucsb.nceas.metacat.util.DocumentUtil;
......
213 214
    
214 215
    /* A reference to a Coordinating Node */
215 216
    private CNode cn;
217
    
218
    // shared executor
219
    private static ExecutorService executor = null;
216 220

  
221
    static {
222
        // use a shared executor service with nThreads == one less than available processors
223
        int availableProcessors = Runtime.getRuntime().availableProcessors();
224
        int nThreads = availableProcessors * 1;
225
        nThreads--;
226
        nThreads = Math.max(1, nThreads);
227
        executor = Executors.newFixedThreadPool(nThreads);  
228
    }
217 229

  
230

  
218 231
    /**
219 232
     * Singleton accessor to get an instance of MNodeService.
220 233
     * 
......
2657 2670
                          logMetacat.info("MNodeService.updateSystemMetadata - calling cn.synchornized in another thread for pid "+id.getValue());
2658 2671
                          this.cNode.synchronize(null, id);
2659 2672
                      } else {
2660
                          logMetacat.warn("MNodeService.updateSystemMetadata - can't update system metadata in CN can't be updated.");
2673
                          logMetacat.warn("MNodeService.updateSystemMetadata - the pid is null. So can't call cn.synchronize to update the system metadata in CN.");
2661 2674
                      }
2662 2675
                  } catch (BaseException e) {
2663 2676
                      e.printStackTrace();
......
2685 2698
              }
2686 2699
          }.init(cn, sysmeta, pid);
2687 2700
          // submit the task, and that's it
2688
          if(MNResourceHandler.getExecutorService() != null) {
2689
              MNResourceHandler.getExecutorService().submit(runner);
2701
          if(executor != null) {
2702
              executor.submit(runner);
2690 2703
          } else {
2691
              logMetacat.error("MNodeSerivce.updateSystemMetadata - since the executor service for submit the change to cn is null, the system metadata change of the id "+pid.getValue()+" can't go to cn by the method through cn.synchronize.");
2704
              logMetacat.warn("MNodeSerivce.updateSystemMetadata - since the executor service for submitting the call of cn.synchronize() is null, the system metadata change of the id "+pid.getValue()+" can't go to cn through cn.synchronize.");
2692 2705
          }
2693 2706
      }
2694 2707
      return success;
src/edu/ucsb/nceas/metacat/restservice/v2/MNResourceHandler.java
1689 1689
        
1690 1690
        MNodeService.getInstance(request).updateSystemMetadata(session, pid, systemMetadata);
1691 1691
	}
1692
	
1693
	/**
1694
     * Get the executor from the service. 
1695
     * @return
1696
     */
1697
    public static ExecutorService getExecutorService() {
1698
        return executor;
1699
    }
1700 1692

  
1701 1693
}

Also available in: Unified diff