當前位置: 首頁>>代碼示例>>Java>>正文


Java ThreadPoolExecutor.CallerRunsPolicy方法代碼示例

本文整理匯總了Java中java.util.concurrent.ThreadPoolExecutor.CallerRunsPolicy方法的典型用法代碼示例。如果您正苦於以下問題:Java ThreadPoolExecutor.CallerRunsPolicy方法的具體用法?Java ThreadPoolExecutor.CallerRunsPolicy怎麽用?Java ThreadPoolExecutor.CallerRunsPolicy使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.util.concurrent.ThreadPoolExecutor的用法示例。


在下文中一共展示了ThreadPoolExecutor.CallerRunsPolicy方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: clearData

import java.util.concurrent.ThreadPoolExecutor; //導入方法依賴的package包/類
private void clearData(Map<File,DataNode> map,TableMigrateInfo table){
	if(table.isError()) {
		return;
	}
	ExecutorService executor  =  new ThreadPoolExecutor(margs.getThreadCount(), margs.getThreadCount(),
               0L, TimeUnit.MILLISECONDS,
               new LinkedBlockingQueue<Runnable>(),new ThreadPoolExecutor.CallerRunsPolicy());
	Iterator<Entry<File,DataNode>>  it = map.entrySet().iterator();
	while(it.hasNext()){
		Entry<File,DataNode> et = it.next();
		File f =et.getKey();
		DataNode srcDn  =  et.getValue();
		executor.execute(new DataClearRunner(table, srcDn, f));
	}
	executor.shutdown();
	while(true){
		if(executor.isTerminated()){
			break;
		}
		try {
			Thread.sleep(200);
		} catch (InterruptedException e) {
			LOGGER.error("error",e);
		}
	}
}
 
開發者ID:huang-up,項目名稱:mycat-src-1.6.1-RELEASE,代碼行數:27,代碼來源:DataMigrator.java

示例2: initDictionaryCaches

import java.util.concurrent.ThreadPoolExecutor; //導入方法依賴的package包/類
private void initDictionaryCaches(DictionaryDAOImpl dictionaryDAO, TenantService tenantService) throws Exception
{
    CompiledModelsCache compiledModelsCache = new CompiledModelsCache();
    compiledModelsCache.setDictionaryDAO(dictionaryDAO);
    compiledModelsCache.setTenantService(tenantService);
    compiledModelsCache.setRegistry(new DefaultAsynchronouslyRefreshedCacheRegistry());
    TraceableThreadFactory threadFactory = new TraceableThreadFactory();
    threadFactory.setThreadDaemon(true);
    threadFactory.setThreadPriority(Thread.NORM_PRIORITY);

    ThreadPoolExecutor threadPoolExecutor = new DynamicallySizedThreadPoolExecutor(20, 20, 90, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(), threadFactory,
            new ThreadPoolExecutor.CallerRunsPolicy());
    compiledModelsCache.setThreadPoolExecutor(threadPoolExecutor);
    dictionaryDAO.setDictionaryRegistryCache(compiledModelsCache);
    dictionaryDAO.init();
}
 
開發者ID:Alfresco,項目名稱:alfresco-repository,代碼行數:17,代碼來源:DictionaryLoadDAOTest.java

示例3: DataMigrator

import java.util.concurrent.ThreadPoolExecutor; //導入方法依賴的package包/類
public DataMigrator(String[] args){
	margs = new DataMigratorArgs(args);
	executor = new ThreadPoolExecutor(margs.getThreadCount(), margs.getThreadCount(),
               0L, TimeUnit.MILLISECONDS,
               new LinkedBlockingQueue<Runnable>(),new ThreadPoolExecutor.CallerRunsPolicy());
	
	
	try {
		createTempParentDir(margs.getTempFileDir());
		ConfigComparer loader = new ConfigComparer(margs.isAwaysUseMaster());
		migrateTables = loader.getMigratorTables();
		//建表
		for(TableMigrateInfo table:migrateTables){
			table.setTableStructure();
			table.createTableToNewDataNodes();
		}
	} catch (Exception e) {
		LOGGER.error(e.getMessage(),e);
		System.out.println(e.getMessage());
		//配置錯誤退出遷移程序
		System.exit(-1);
	}
}
 
開發者ID:huang-up,項目名稱:mycat-src-1.6.1-RELEASE,代碼行數:24,代碼來源:DataMigrator.java

示例4: migrateData

import java.util.concurrent.ThreadPoolExecutor; //導入方法依賴的package包/類
private void migrateData() throws SQLException{
	executor =  new ThreadPoolExecutor(margs.getThreadCount(), margs.getThreadCount(),
               0L, TimeUnit.MILLISECONDS,
               new LinkedBlockingQueue<Runnable>(),new ThreadPoolExecutor.CallerRunsPolicy());
	for(TableMigrateInfo table:migrateTables){
		if(!table.isError()){ //忽略已出錯的拆分表
			List<DataNodeMigrateInfo> detailList = table.getDataNodesDetail();
			for(DataNodeMigrateInfo info:detailList){
				executor.execute(new DataMigrateRunner(table, info.getSrc(), info.getTarget(), table.getTableName(), info.getTempFile()));
			}
		}
	}
	executor.shutdown();
	while(true){
		if(executor.isTerminated()){
			break;
		}
		try {
			Thread.sleep(200);
		} catch (InterruptedException e) {
			LOGGER.error("error",e);
		}
	}
}
 
開發者ID:huang-up,項目名稱:mycat-src-1.6.1-RELEASE,代碼行數:25,代碼來源:DataMigrator.java

示例5: createInstance

import java.util.concurrent.ThreadPoolExecutor; //導入方法依賴的package包/類
private DynamicallySizedThreadPoolExecutor createInstance(int corePoolSize, int maximumPoolSize, int keepAliveTime)
{
    // We need a thread factory
    TraceableThreadFactory threadFactory = new TraceableThreadFactory();
    threadFactory.setThreadDaemon(true);
    threadFactory.setThreadPriority(Thread.NORM_PRIORITY);

    BlockingQueue<Runnable> workQueue = new LinkedBlockingQueue<Runnable>();

    return new DynamicallySizedThreadPoolExecutor(
            corePoolSize,
            maximumPoolSize,
            keepAliveTime,
            TimeUnit.SECONDS,
            workQueue,
            threadFactory,
            new ThreadPoolExecutor.CallerRunsPolicy());
}
 
開發者ID:Alfresco,項目名稱:alfresco-core,代碼行數:19,代碼來源:DynamicallySizedThreadPoolExecutorTest.java

示例6: initDictionaryCaches

import java.util.concurrent.ThreadPoolExecutor; //導入方法依賴的package包/類
void initDictionaryCaches(DictionaryDAOImpl dictionaryDAO, TenantService tenantService)
{
    CompiledModelsCache compiledModelsCache = new CompiledModelsCache();
    compiledModelsCache.setDictionaryDAO(dictionaryDAO);
    compiledModelsCache.setTenantService(tenantService);
    compiledModelsCache.setRegistry(new DefaultAsynchronouslyRefreshedCacheRegistry());
    TraceableThreadFactory threadFactory = new TraceableThreadFactory();
    threadFactory.setThreadDaemon(true);
    threadFactory.setThreadPriority(Thread.NORM_PRIORITY);

    ThreadPoolExecutor threadPoolExecutor = new DynamicallySizedThreadPoolExecutor(20, 20, 90, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(), threadFactory,
            new ThreadPoolExecutor.CallerRunsPolicy());
    compiledModelsCache.setThreadPoolExecutor(threadPoolExecutor);
    dictionaryDAO.setDictionaryRegistryCache(compiledModelsCache);
    dictionaryDAO.init();
}
 
開發者ID:Alfresco,項目名稱:alfresco-data-model,代碼行數:17,代碼來源:AbstractModelTest.java

示例7: afterPropertiesSet

import java.util.concurrent.ThreadPoolExecutor; //導入方法依賴的package包/類
public void afterPropertiesSet() throws Exception {
    scheduler = new ScheduledThreadPoolExecutor(1, new NamedThreadFactory("Otter-Statistics-Table"),
                                                new ThreadPoolExecutor.CallerRunsPolicy());
    if (statUnit > 0) {
        scheduler.scheduleAtFixedRate(new Runnable() {

            public void run() {
                try {
                    flushBehaviorHistory();
                } catch (Exception e) {
                    logger.error("flush delay stat failed!", e);
                }
            }
        }, statUnit, statUnit, TimeUnit.MILLISECONDS);
    }
}
 
開發者ID:luoyaogui,項目名稱:otter-G,代碼行數:17,代碼來源:TableStatServiceImpl.java

示例8: createExecutor

import java.util.concurrent.ThreadPoolExecutor; //導入方法依賴的package包/類
private static PooledExecutorWithDMStats createExecutor(PoolStatHelper poolHelper,
    final ThreadGroup threadGroup) {
  ThreadFactory factory = new ThreadFactory() {
    private final AtomicInteger threadNum = new AtomicInteger();

    public Thread newThread(Runnable r) {
      Thread thread = new Thread(threadGroup, r,
          "locator request thread[" + threadNum.incrementAndGet() + "]");
      thread.setDaemon(true);
      return thread;
    }
  };

  return new PooledExecutorWithDMStats(new SynchronousQueue(), MAX_POOL_SIZE, poolHelper, factory,
      POOL_IDLE_TIMEOUT, new ThreadPoolExecutor.CallerRunsPolicy());
}
 
開發者ID:ampool,項目名稱:monarch,代碼行數:17,代碼來源:TcpServer.java

示例9: Exporter

import java.util.concurrent.ThreadPoolExecutor; //導入方法依賴的package包/類
public Exporter(String urlBase, String username, String password, int threads, Config conf, boolean verbose, boolean useTempFile, int maxRows,
		KeyStore extendedTrust)
		throws IOException, HttpException, KeyStoreException, NoSuchAlgorithmException, KeyManagementException, ExporterException {
	if(conf != null)  {
		this.rspFactory = rspFactories.get(conf.getOutputFormat());
		if(rspFactory == null)
			throw new ExporterException("Unknown output format: " + conf.getOutputFormat());
	}
		
	
	this.verbose = verbose;
	this.useTempFile = useTempFile;
	this.conf = conf;
	this.maxRows = maxRows;
	this.client = new Client(urlBase, username, password, threads, extendedTrust);
	
	// Calling this with a null conf is only valid if we're printing field names and nothing else. 
	// Everything else will crash miserably! (Yeah, this is a bit of a hack...)
	//
	if(conf != null) {
		this.registerFields();
	}
	this.executor = new ThreadPoolExecutor(threads, threads, 5, TimeUnit.SECONDS,
				new ArrayBlockingQueue<>(20), new ThreadPoolExecutor.CallerRunsPolicy());
}
 
開發者ID:prydin,項目名稱:vrops-export,代碼行數:26,代碼來源:Exporter.java

示例10: onInit

import java.util.concurrent.ThreadPoolExecutor; //導入方法依賴的package包/類
@Override
protected void onInit() throws Exception {
    RxNetty.useMetricListenersFactory(new ServoEventsListenerFactory());
    documentClient = new DocumentClient(cfg.getServiceEndpoint(), cfg.getMasterKey(),
            cfg.getConnectionPolicy(), cfg.getConsistencyLevel());
    
    ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(cfg.getConcurrency(), cfg.getConcurrency(),
            10, TimeUnit.MINUTES, new ArrayBlockingQueue<Runnable>(cfg.getConcurrency(), true),
            new ThreadPoolExecutor.CallerRunsPolicy());

    this.executor = MoreExecutors.listeningDecorator(threadPoolExecutor);
}
 
開發者ID:Azure,項目名稱:azure-documentdb-rxjava,代碼行數:13,代碼來源:SyncBulkInsertBenchmark.java

示例11: RxWrapperDocumentClientImpl

import java.util.concurrent.ThreadPoolExecutor; //導入方法依賴的package包/類
public RxWrapperDocumentClientImpl(DocumentClient client) {
    this.client = client;

    int maxThreads = (int) (client.getConnectionPolicy().getMaxPoolSize() * 1.1);
    this.executorService =  new ThreadPoolExecutor(
            Math.min(8, maxThreads), // core thread pool size
            maxThreads, // maximum thread pool size
            30, // time to wait before killing idle threads
            TimeUnit.SECONDS, 
            new SynchronousQueue<>(),
            new RxThreadFactory("RxDocdb-io"),
            new ThreadPoolExecutor.CallerRunsPolicy());
    this.scheduler = Schedulers.from(executorService);
}
 
開發者ID:Azure,項目名稱:azure-documentdb-rxjava,代碼行數:15,代碼來源:RxWrapperDocumentClientImpl.java

示例12: DownloadTask

import java.util.concurrent.ThreadPoolExecutor; //導入方法依賴的package包/類
/**
 * 構建文件下載器,適用於下載單個大文件
 *
 * @param downloadUrl 下載路徑
 * @param fileSaveDir 文件保存目錄
 * @param threadNum   下載線程數
 */
public DownloadTask(Context context, String downloadUrl, File fileSaveDir, int threadNum) {
    try {
        System.out.println("DownloadTask>>>" + downloadUrl);
        this.context = context;
        this.downloadUrl = downloadUrl;
        fileService = FileService.getInstance();
        URL url = new URL(this.downloadUrl);
        if (!fileSaveDir.exists())
            fileSaveDir.mkdirs();
        this.threadnum = threadNum;
        threadPool = new ThreadPoolExecutor(threadnum + 1, threadnum + 1, 20, TimeUnit.SECONDS, new LinkedBlockingDeque<Runnable>(), new ThreadPoolExecutor.CallerRunsPolicy());
        HttpURLConnection conn = getConnectionAndConnect(url, 3);
        this.fileSize = conn.getContentLength();//根據響應獲取文件大小
        if (this.fileSize <= 0)
            throw new RuntimeException("Unkown file size ");

        String filename = getFileName(conn);
        this.saveFile = new File(fileSaveDir, filename);/* 保存文件 */
        Map<Integer, Integer> logdata = fileService.getData(downloadUrl);
        if (logdata.size() > 0) {
            for (Map.Entry<Integer, Integer> entry : logdata.entrySet())
                data.put(entry.getKey(), entry.getValue());
        }
        this.block = (this.fileSize % threadnum) == 0 ? this.fileSize / threadnum : this.fileSize / threadnum + 1;
        if (this.data.size() == threadnum) {
            for (int i = 0; i < threadnum; i++) {
                this.downloadSize += this.data.get(i);
            }
            Log.i(TAG, "已經下載的長度" + this.downloadSize);
        }
    } catch (Exception e) {
        e.printStackTrace();
        throw new RuntimeException("don't connection this url");
    }
}
 
開發者ID:LingjuAI,項目名稱:AssistantBySDK,代碼行數:43,代碼來源:DownloadTask.java

示例13: mark

import java.util.concurrent.ThreadPoolExecutor; //導入方法依賴的package包/類
/**
 * Marks all of the submissions.
 * @param threads The thread-pool size to use in marking the assignments
 */
public void mark(final int threads)
    throws Exception {
    final ProgressBar pb = new ProgressBar("Marking", this.submissions.size());
    pb.start();
    final CountDownLatch latch = new CountDownLatch(this.submissions.size());
    final ThreadPoolExecutor executor = new ThreadPoolExecutor(
        threads,
        threads,
        0L,
        TimeUnit.MILLISECONDS,
        new ArrayBlockingQueue<>(threads),
        new ThreadPoolExecutor.CallerRunsPolicy()
    );
    for (Submission s : this.submissions) {
        executor.submit(() -> {
            try {
                s.results(this.markingResults(s.directory()));
                pb.step();
            } catch (Exception e) {
                throw new RuntimeException(e);
            } finally {
                latch.countDown();
            }
        });
    }
    executor.shutdown();
    latch.await();
    pb.stop();
}
 
開發者ID:jachinte,項目名稱:grade-buddy,代碼行數:34,代碼來源:AutomatedMarking.java

示例14: afterPropertiesSet

import java.util.concurrent.ThreadPoolExecutor; //導入方法依賴的package包/類
public void afterPropertiesSet() throws Exception {
    executor = new ThreadPoolExecutor(poolSize,
        poolSize,
        0L,
        TimeUnit.MILLISECONDS,
        new ArrayBlockingQueue(poolSize * 4),
        new NamedThreadFactory(WORKER_NAME),
        new ThreadPoolExecutor.CallerRunsPolicy());
}
 
開發者ID:luoyaogui,項目名稱:otter-G,代碼行數:10,代碼來源:DatabaseExtractor.java

示例15: start

import java.util.concurrent.ThreadPoolExecutor; //導入方法依賴的package包/類
@Override
public void start() {
  this.executor = new ThreadPoolExecutor(
      handlerCount,
      handlerCount,
      60,
      TimeUnit.SECONDS,
      new ArrayBlockingQueue<Runnable>(maxQueueLength),
      new DaemonThreadFactory("FifoRpcScheduler.handler"),
      new ThreadPoolExecutor.CallerRunsPolicy());
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:12,代碼來源:FifoRpcScheduler.java


注:本文中的java.util.concurrent.ThreadPoolExecutor.CallerRunsPolicy方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。