本文整理汇总了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);
}
}
}
示例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();
}
示例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);
}
}
示例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);
}
}
}
示例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());
}
示例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();
}
示例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);
}
}
示例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());
}
示例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());
}
示例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);
}
示例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);
}
示例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");
}
}
示例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();
}
示例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());
}
示例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());
}