当前位置: 首页>>代码示例>>Java>>正文


Java AbortPolicy类代码示例

本文整理汇总了Java中java.util.concurrent.ThreadPoolExecutor.AbortPolicy的典型用法代码示例。如果您正苦于以下问题:Java AbortPolicy类的具体用法?Java AbortPolicy怎么用?Java AbortPolicy使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


AbortPolicy类属于java.util.concurrent.ThreadPoolExecutor包,在下文中一共展示了AbortPolicy类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testStandardRejectedExecutionHandlers

import java.util.concurrent.ThreadPoolExecutor.AbortPolicy; //导入依赖的package包/类
/** Directly test simple ThreadPoolExecutor RejectedExecutionHandlers. */
public void testStandardRejectedExecutionHandlers() {
    final ThreadPoolExecutor p =
        new ThreadPoolExecutor(1, 1, 1, SECONDS,
                               new ArrayBlockingQueue<Runnable>(1));
    final AtomicReference<Thread> thread = new AtomicReference<>();
    final Runnable r = new Runnable() { public void run() {
        thread.set(Thread.currentThread()); }};

    try {
        new AbortPolicy().rejectedExecution(r, p);
        shouldThrow();
    } catch (RejectedExecutionException success) {}
    assertNull(thread.get());

    new DiscardPolicy().rejectedExecution(r, p);
    assertNull(thread.get());

    new CallerRunsPolicy().rejectedExecution(r, p);
    assertSame(Thread.currentThread(), thread.get());

    // check that pool was not perturbed by handlers
    assertTrue(p.getRejectedExecutionHandler() instanceof AbortPolicy);
    assertEquals(0, p.getTaskCount());
    assertTrue(p.getQueue().isEmpty());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:27,代码来源:ThreadPoolExecutorTest.java

示例2: execute

import java.util.concurrent.ThreadPoolExecutor.AbortPolicy; //导入依赖的package包/类
/** 执行任务,当线程池处于关闭,将会重新创建新的线程池 */
public synchronized void execute(Runnable run) {
	if (run == null) {
		return;
	}
	if (mPool == null || mPool.isShutdown()) {
		//参数说明
		//当线程池中的线程小于mCorePoolSize,直接创建新的线程加入线程池执行任务
		//当线程池中的线程数目等于mCorePoolSize,将会把任务放入任务队列BlockingQueue中
		//当BlockingQueue中的任务放满了,将会创建新的线程去执行,
		//但是当总线程数大于mMaximumPoolSize时,将会抛出异常,交给RejectedExecutionHandler处理
		//mKeepAliveTime是线程执行完任务后,且队列中没有可以执行的任务,存活的时间,后面的参数是时间单位
		//ThreadFactory是每次创建新的线程工厂
		mPool = new ThreadPoolExecutor(mCorePoolSize, mMaximumPoolSize, mKeepAliveTime, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>(), Executors.defaultThreadFactory(), new AbortPolicy());
	}
	mPool.execute(run);
}
 
开发者ID:cuilitang,项目名称:CuiMarket,代码行数:18,代码来源:ThreadManager.java

示例3: QuartzThreadPool

import java.util.concurrent.ThreadPoolExecutor.AbortPolicy; //导入依赖的package包/类
public QuartzThreadPool(final int poolSize) {
  checkArgument(poolSize > 0, "Pool size must be greater than zero");

  this.threadPoolExecutor = new NexusThreadPoolExecutor(
      poolSize, // core-size
      poolSize, // max-size
      0L, // keep-alive
      TimeUnit.MILLISECONDS,
      new SynchronousQueue<>(), // no queuing
      new NexusThreadFactory("quartz", "nx-tasks"),
      new AbortPolicy());

  // wrapper for Shiro integration
  this.nexusExecutorService = NexusExecutorService.forFixedSubject(
      threadPoolExecutor, FakeAlmightySubject.TASK_SUBJECT);
}
 
开发者ID:sonatype,项目名称:nexus-public,代码行数:17,代码来源:QuartzThreadPool.java

示例4: connect

import java.util.concurrent.ThreadPoolExecutor.AbortPolicy; //导入依赖的package包/类
/**
 * 连接到线上服务器。
 */
public void connect() throws LinkException {
    if (!connected.compareAndSet(false, true)) {
        return;
    }
    if (this.removeDuplicate) {
        this.tmcHandler = new DuplicateRemoverTmcHandler(this);
    } else {
        this.tmcHandler = new TmcHandler(this);
    }
    this.client.setMessageHandler(this.tmcHandler);
    this.threadPool = new ThreadPoolExecutor(threadCount, threadCount, fetchPeriod * 2,
            TimeUnit.MICROSECONDS, new ArrayBlockingQueue<Runnable>(queueSize),
            new NamedThreadFactory("tmc-worker"), new AbortPolicy());
    try {
        this.client.connect(uri);
    } catch (LinkException e) {
        connected.set(false);
        throw e;
    }
    this.doPullRequest();
}
 
开发者ID:kuiwang,项目名称:my-dev,代码行数:25,代码来源:TmcClient.java

示例5: a

import java.util.concurrent.ThreadPoolExecutor.AbortPolicy; //导入依赖的package包/类
public final synchronized void a(Runnable runnable) {
    if (runnable != null) {
        try {
            if (this.a == null || this.a.isShutdown()) {
                this.a = new ThreadPoolExecutor(this.b, this.c, this.d, TimeUnit.MILLISECONDS, new LinkedBlockingQueue(), Executors.defaultThreadFactory(), new AbortPolicy());
            }
            this.a.execute(runnable);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:13,代码来源:d.java

示例6: testDefaultRejectedExecutionHandler

import java.util.concurrent.ThreadPoolExecutor.AbortPolicy; //导入依赖的package包/类
/**
 * The default rejected execution handler is AbortPolicy.
 */
public void testDefaultRejectedExecutionHandler() {
    final ThreadPoolExecutor p =
        new ThreadPoolExecutor(1, 2,
                               LONG_DELAY_MS, MILLISECONDS,
                               new ArrayBlockingQueue<Runnable>(10));
    try (PoolCleaner cleaner = cleaner(p)) {
        assertTrue(p.getRejectedExecutionHandler() instanceof AbortPolicy);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:13,代码来源:ThreadPoolExecutorTest.java

示例7: VSphereAdapterResourceEnumerationService

import java.util.concurrent.ThreadPoolExecutor.AbortPolicy; //导入依赖的package包/类
public VSphereAdapterResourceEnumerationService() {
    this.enumerationThreadPool = new ThreadPoolExecutor(MAX_CONCURRENT_ENUM_PROCESSES,
            MAX_CONCURRENT_ENUM_PROCESSES,
            0L, TimeUnit.MILLISECONDS,
            new SynchronousQueue<>(),
            new AbortPolicy());

    this.tagCache = new TagCache();
}
 
开发者ID:vmware,项目名称:photon-model,代码行数:10,代码来源:VSphereAdapterResourceEnumerationService.java

示例8: execute

import java.util.concurrent.ThreadPoolExecutor.AbortPolicy; //导入依赖的package包/类
public void execute(Runnable r) {
	if (executor == null) {
		executor = new ThreadPoolExecutor(corePoolSize,
				maximumPoolSize, keepAliveTime, TimeUnit.SECONDS,
				new LinkedBlockingQueue<Runnable>(),
				Executors.defaultThreadFactory(), new AbortPolicy());
		// 参1:核心线程数;参2:最大线程数;参3:线程休眠时间;参4:时间单位;参5:线程队列;参6:生产线程的工厂;参7:线程异常处理策略
	}

	// 线程池执行一个Runnable对象, 具体运行时机线程池说了算
	executor.execute(r);
}
 
开发者ID:liaozhoubei,项目名称:NetEasyNews,代码行数:13,代码来源:ThreadManager.java

示例9: executor

import java.util.concurrent.ThreadPoolExecutor.AbortPolicy; //导入依赖的package包/类
@Bean(destroyMethod = "shutdown")
public ExecutorService executor(final Tracer tracer) {
    return TracingExecutors.preserve(
            new ThreadPoolExecutor(
                    1, 20, 1, MINUTES,
                    new ArrayBlockingQueue<>(0),
                    new CustomizableThreadFactory("http-example-"),
                    new AbortPolicy()),
            tracer);
}
 
开发者ID:zalando,项目名称:riptide,代码行数:11,代码来源:ManualConfiguration.java

示例10: execute

import java.util.concurrent.ThreadPoolExecutor.AbortPolicy; //导入依赖的package包/类
/**
 * 执行任务,当线程池处于关闭,将会重新创建新的线程池
 */
public synchronized void execute(Runnable run) {
    if (run == null) {
        return;
    }
    if (mPool == null || mPool.isShutdown()) {
        mPool = new ThreadPoolExecutor(mCorePoolSize, mMaximumPoolSize, mKeepAliveTime, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>(), Executors.defaultThreadFactory(), new AbortPolicy());
    }
    mPool.execute(run);
}
 
开发者ID:g977284333,项目名称:KwPresent,代码行数:13,代码来源:ThreadManager.java

示例11: newFixedThreadPool

import java.util.concurrent.ThreadPoolExecutor.AbortPolicy; //导入依赖的package包/类
/**
 * Create a new {@link ObservableExecutorService} with the given 
 * fixed pool size. See {@link Executors#newFixedThreadPool(int)}
 * for details. 
 *  
 * @param poolSize The pool size
 * @return The {@link ObservableExecutorService}
 */
public static ObservableExecutorService newFixedThreadPool(int poolSize)
{
    return new ObservableExecutorService(
        poolSize, poolSize, 
        0L, TimeUnit.MILLISECONDS,
        new LinkedBlockingQueue<Runnable>(),
        Executors.defaultThreadFactory(), new AbortPolicy());
}
 
开发者ID:javagl,项目名称:SwingTasks,代码行数:17,代码来源:ObservableExecutors.java

示例12: newCachedThreadPool

import java.util.concurrent.ThreadPoolExecutor.AbortPolicy; //导入依赖的package包/类
/**
 * Create a new {@link ObservableExecutorService} with a cached thread
 * pool. See {@link Executors#newCachedThreadPool()}.
 * 
 * @return The {@link ObservableExecutorService}
 */
public static ObservableExecutorService newCachedThreadPool()
{
    return new ObservableExecutorService(
        0, Integer.MAX_VALUE,
        60L, TimeUnit.SECONDS, 
        new SynchronousQueue<Runnable>(),
        Executors.defaultThreadFactory(), new AbortPolicy());
}
 
开发者ID:javagl,项目名称:SwingTasks,代码行数:15,代码来源:ObservableExecutors.java

示例13: newDefaultThreadPool

import java.util.concurrent.ThreadPoolExecutor.AbortPolicy; //导入依赖的package包/类
static ThreadPoolExecutor newDefaultThreadPool() {
    final ThreadPoolExecutor result = new ThreadPoolExecutor(
            // Bound the pool. Most foreground dependency managers should be called only very rarely, so
            //  keep a minimal core pool around and only grow it on demand.
            1, 16,
            // Threads will be kept alive in an idle state for a minute or two. After that, they may be
            //  garbage-collected, so that we're keeping a larger thread pool only during weird periods of
            //  congestion. (Note: the background manager will typically keep all threads pretty active, since it's
            //  repeatedly launching new pingers. The live manager will spin them up and down based on traffic to
            //  the rather uncommonly used /healthcheck/live uri).
            30, TimeUnit.SECONDS,
            // Use a blocking queue just to keep track of checks when the world is going wrong. This is mostly useful
            //  when we're adding a bunch of checks at the same time, such as during a live healthcheck. Might as well
            //  keep this pretty small, because any nontrivial wait to execute is going to blow up a timeout anyway.
            new SynchronousQueue<Runnable>(),
            // Name your threads.
            new ThreadFactoryBuilder()
                    .setNameFormat("dependency-default-" + DEFAULT_THREAD_POOL_COUNT.getAndIncrement() + "-checker-%d")
                    .setDaemon(true)
                    .setUncaughtExceptionHandler(new UncaughtExceptionHandler() {
                        @Override
                        public void uncaughtException(Thread t, Throwable e) {
                            Logger.getLogger(AbstractDependencyManager.class)
                                    .error("Uncaught throwable in thread " + t.getName() + "/" + t.getId(), e);
                        }
                    })
                    .build(),
            // Explicitly restating the default policy here, because healthchecks should Just Not Work if there
            //  are insufficient resources to support them. Given the smallish queue above, this means that
            //  we're going to end up throwing exceptions if we get too blocked up somehow.
            new AbortPolicy());

    result.prestartAllCoreThreads();

    return result;
}
 
开发者ID:indeedeng,项目名称:status,代码行数:37,代码来源:AbstractDependencyManager.java

示例14: getHandler

import java.util.concurrent.ThreadPoolExecutor.AbortPolicy; //导入依赖的package包/类
@Override
RejectedExecutionHandler getHandler() {
    return new ThreadPoolExecutor.AbortPolicy();
}
 
开发者ID:NessComputing,项目名称:components-ness-executors,代码行数:5,代码来源:ThreadPoolConfiguration.java


注:本文中的java.util.concurrent.ThreadPoolExecutor.AbortPolicy类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。