ACCUMULO-2270 Make initialization of static threadpool thread-safe Signed-off-by: Bill Havanki <bhava...@cloudera.com>
Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/9231648a Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/9231648a Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/9231648a Branch: refs/heads/1.6.0-SNAPSHOT Commit: 9231648ae1d7795456970f858b37f6bfc110e6ca Parents: d2da431 Author: Vikram Srivastava <vikr...@cloudera.com> Authored: Tue Jan 28 23:29:10 2014 -0800 Committer: Bill Havanki <bhava...@cloudera.com> Committed: Fri Mar 7 10:45:49 2014 -0500 ---------------------------------------------------------------------- .../org/apache/accumulo/master/tableOps/BulkImport.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/accumulo/blob/9231648a/server/master/src/main/java/org/apache/accumulo/master/tableOps/BulkImport.java ---------------------------------------------------------------------- diff --git a/server/master/src/main/java/org/apache/accumulo/master/tableOps/BulkImport.java b/server/master/src/main/java/org/apache/accumulo/master/tableOps/BulkImport.java index 430f14d..bdc89dd 100644 --- a/server/master/src/main/java/org/apache/accumulo/master/tableOps/BulkImport.java +++ b/server/master/src/main/java/org/apache/accumulo/master/tableOps/BulkImport.java @@ -484,19 +484,20 @@ class LoadFiles extends MasterRepo { return 500; return 0; } - - synchronized void initializeThreadPool(Master master) { + + private static synchronized ExecutorService getThreadPool(Master master) { if (threadPool == null) { int threadPoolSize = master.getSystemConfiguration().getCount(Property.MASTER_BULK_THREADPOOL_SIZE); ThreadPoolExecutor pool = new SimpleThreadPool(threadPoolSize, "bulk import"); pool.allowCoreThreadTimeOut(true); threadPool = new TraceExecutorService(pool); } + return threadPool; } - + @Override public Repo<Master> call(final long tid, final Master master) throws Exception { - initializeThreadPool(master); + ExecutorService executor = getThreadPool(master); final SiteConfiguration conf = ServerConfiguration.getSiteConfiguration(); VolumeManager fs = master.getFileSystem(); List<FileStatus> files = new ArrayList<FileStatus>(); @@ -533,7 +534,7 @@ class LoadFiles extends MasterRepo { // Use the threadpool to assign files one-at-a-time to the server final List<String> loaded = Collections.synchronizedList(new ArrayList<String>()); for (final String file : filesToLoad) { - results.add(threadPool.submit(new Callable<List<String>>() { + results.add(executor.submit(new Callable<List<String>>() { @Override public List<String> call() { List<String> failures = new ArrayList<String>();