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


Java ThreadPoolRejectedPolicy类代码示例

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


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

示例1: threadPoolProfile

import org.apache.camel.ThreadPoolRejectedPolicy; //导入依赖的package包/类
/**  
	* thread pool of consumer
	*/
	@Bean(name="defaultThreadPoolProfile")
	ThreadPoolProfile threadPoolProfile(){
		ThreadPoolProfile defaultThreadPoolProfile = new ThreadPoolProfile();
		defaultThreadPoolProfile.setDefaultProfile(true);
		defaultThreadPoolProfile.setId("defaultThreadPoolProfile");
		defaultThreadPoolProfile.setPoolSize(threadPoolSize);
		defaultThreadPoolProfile.setMaxPoolSize(threadMaxPoolSize);
		defaultThreadPoolProfile.setMaxQueueSize(threadMaxQueueSize); // 队列最大程度1000万
		defaultThreadPoolProfile.setTimeUnit(TimeUnit.SECONDS);
		defaultThreadPoolProfile.setKeepAliveTime(60 * 5L);
		defaultThreadPoolProfile.setRejectedPolicy(ThreadPoolRejectedPolicy.CallerRuns);
//		camelContext().getExecutorServiceManager().registerThreadPoolProfile(defaultThreadPoolProfile);
//		setDefaultThreadPoolProfile(defaultThreadPoolProfile);
		return defaultThreadPoolProfile;
	}
 
开发者ID:eXcellme,项目名称:eds,代码行数:19,代码来源:EdsCamelConfig.java

示例2: createRouteBuilder

import org.apache.camel.ThreadPoolRejectedPolicy; //导入依赖的package包/类
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            // create and register thread pool profile
            ThreadPoolProfile profile = new ThreadPoolProfile("myProfile");
            profile.setPoolSize(2);
            profile.setMaxPoolSize(8);
            profile.setRejectedPolicy(ThreadPoolRejectedPolicy.Abort);
            context.getExecutorServiceManager().registerThreadPoolProfile(profile);

            from("direct:start")
                .aggregate(header("id"), new BodyInAggregatingStrategy())
                    // use our custom thread pool profile
                    .completionSize(3).executorServiceRef("myProfile")
                    .to("log:foo")
                    .to("mock:aggregated");
        }
    };
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:22,代码来源:AggregateThreadPoolProfileTest.java

示例3: createRouteBuilder

import org.apache.camel.ThreadPoolRejectedPolicy; //导入依赖的package包/类
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            ThreadPoolProfile profile = new ThreadPoolProfile("custom");
            profile.setPoolSize(5);
            profile.setMaxPoolSize(15);
            profile.setKeepAliveTime(25L);
            profile.setMaxQueueSize(250);
            profile.setRejectedPolicy(ThreadPoolRejectedPolicy.Abort);

            context.getExecutorServiceManager().registerThreadPoolProfile(profile);

            from("direct:start").threads().executorServiceRef("custom").to("mock:result");

            from("direct:foo").threads().executorServiceRef("custom").to("mock:foo");
        }
    };
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:21,代码来源:DualManagedThreadPoolProfileTest.java

示例4: createRouteBuilder

import org.apache.camel.ThreadPoolRejectedPolicy; //导入依赖的package包/类
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            ThreadPoolProfile profile = new ThreadPoolProfile("custom");
            profile.setPoolSize(5);
            profile.setMaxPoolSize(15);
            profile.setKeepAliveTime(25L);
            profile.setMaxQueueSize(250);
            profile.setAllowCoreThreadTimeOut(true);
            profile.setRejectedPolicy(ThreadPoolRejectedPolicy.Abort);

            context.getExecutorServiceManager().registerThreadPoolProfile(profile);

            from("direct:start").threads().executorServiceRef("custom").to("mock:result");
        }
    };
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:20,代码来源:ManagedThreadPoolProfileTest.java

示例5: testGetThreadPoolProfileInheritCustomDefaultValues

import org.apache.camel.ThreadPoolRejectedPolicy; //导入依赖的package包/类
public void testGetThreadPoolProfileInheritCustomDefaultValues() throws Exception {
    ThreadPoolProfile newDefault = new ThreadPoolProfile("newDefault");
    newDefault.setKeepAliveTime(30L);
    newDefault.setMaxPoolSize(50);
    newDefault.setPoolSize(5);
    newDefault.setMaxQueueSize(2000);
    newDefault.setRejectedPolicy(ThreadPoolRejectedPolicy.Abort);
    context.getExecutorServiceManager().setDefaultThreadPoolProfile(newDefault);

    assertNull(context.getExecutorServiceManager().getThreadPoolProfile("foo"));
    ThreadPoolProfile foo = new ThreadPoolProfile("foo");
    foo.setMaxPoolSize(25);
    foo.setPoolSize(1);
    context.getExecutorServiceManager().registerThreadPoolProfile(foo);
    assertSame(foo, context.getExecutorServiceManager().getThreadPoolProfile("foo"));

    ExecutorService executor = context.getExecutorServiceManager().newThreadPool(this, "MyPool", "foo");

    ThreadPoolExecutor tp = assertIsInstanceOf(ThreadPoolExecutor.class, executor);
    assertEquals(25, tp.getMaximumPoolSize());
    // should inherit the default values
    assertEquals(1, tp.getCorePoolSize());
    assertEquals(30, tp.getKeepAliveTime(TimeUnit.SECONDS));
    assertEquals("Abort", tp.getRejectedExecutionHandler().toString());
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:26,代码来源:DefaultExecutorServiceManagerTest.java

示例6: testGetThreadPoolProfileInheritCustomDefaultValues

import org.apache.camel.ThreadPoolRejectedPolicy; //导入依赖的package包/类
public void testGetThreadPoolProfileInheritCustomDefaultValues() throws Exception {
    ThreadPoolProfileSupport newDefault = new ThreadPoolProfileSupport("newDefault");
    newDefault.setKeepAliveTime(30L);
    newDefault.setMaxPoolSize(50);
    newDefault.setPoolSize(5);
    newDefault.setMaxQueueSize(2000);
    newDefault.setRejectedPolicy(ThreadPoolRejectedPolicy.Abort);
    context.getExecutorServiceStrategy().setDefaultThreadPoolProfile(newDefault);

    assertNull(context.getExecutorServiceStrategy().getThreadPoolProfile("foo"));
    ThreadPoolProfileSupport foo = new ThreadPoolProfileSupport("foo");
    foo.setMaxPoolSize(25);
    foo.setPoolSize(1);
    context.getExecutorServiceStrategy().registerThreadPoolProfile(foo);
    assertSame(foo, context.getExecutorServiceStrategy().getThreadPoolProfile("foo"));

    ExecutorService executor = context.getExecutorServiceStrategy().newThreadPool(this, "MyPool", "foo");

    ThreadPoolExecutor tp = assertIsInstanceOf(ThreadPoolExecutor.class, executor);
    assertEquals(25, tp.getMaximumPoolSize());
    // should inherit the default values
    assertEquals(1, tp.getCorePoolSize());
    assertEquals(30, tp.getKeepAliveTime(TimeUnit.SECONDS));
    assertEquals("Abort", tp.getRejectedExecutionHandler().toString());
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:26,代码来源:DefaultExecutorServiceStrategyTest.java

示例7: testAsyncRouting

import org.apache.camel.ThreadPoolRejectedPolicy; //导入依赖的package包/类
public void testAsyncRouting() throws Exception {
    final int threads = 5;

    // should trigger many tasks as we are async
    getMockEndpoint("mock:task").expectedMinimumMessageCount(20);

    context.addRoutes(new RouteBuilder() {
        public void configure() {
            from("timer://foo?fixedRate=true&delay=0&period=200").id("timer")
                    .threads(threads, threads).maxQueueSize(1).rejectedPolicy(ThreadPoolRejectedPolicy.CallerRuns)
                    .to("log:task")
                    .to("mock:task")
                    .process(new Processor() {
                        public void process(Exchange exchange) throws Exception {
                            // simulate long task
                            TimeUnit.SECONDS.sleep(1);
                        }
                    });
        }
    });
    context.start();

    assertMockEndpointsSatisfied();
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:25,代码来源:TimerAsyncTest.java

示例8: testBigProfile

import org.apache.camel.ThreadPoolRejectedPolicy; //导入依赖的package包/类
public void testBigProfile() throws Exception {
    CamelContext context = getMandatoryBean(CamelContext.class, "camel-C");

    ThreadPoolProfile profile = context.getExecutorServiceManager().getThreadPoolProfile("big");
    assertEquals(50, profile.getPoolSize().intValue());
    assertEquals(100, profile.getMaxPoolSize().intValue());
    assertEquals(ThreadPoolRejectedPolicy.DiscardOldest, profile.getRejectedPolicy());
    assertEquals(null, profile.getKeepAliveTime());
    assertEquals(null, profile.getMaxQueueSize());

    // create a thread pool from big
    ExecutorService executor = context.getExecutorServiceManager().newThreadPool(this, "MyBig", "big");
    ThreadPoolExecutor tp = assertIsInstanceOf(ThreadPoolExecutor.class, executor);
    assertEquals(50, tp.getCorePoolSize());
    assertEquals(100, tp.getMaximumPoolSize());
    // should inherit default options
    assertEquals(60, tp.getKeepAliveTime(TimeUnit.SECONDS));
    assertEquals("DiscardOldest", tp.getRejectedExecutionHandler().toString());
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:20,代码来源:SpringCamelContextThreadPoolProfilesTest.java

示例9: threadPoolProfileRemote

import org.apache.camel.ThreadPoolRejectedPolicy; //导入依赖的package包/类
private ThreadPoolProfile threadPoolProfileRemote() {
	//Define custom thread pool profile
	ThreadPoolProfile threadPoolProfile = new ThreadPoolProfile("openex-remote-thread-profile");
	threadPoolProfile.setPoolSize(10);
	threadPoolProfile.setMaxPoolSize(20);
	threadPoolProfile.setMaxQueueSize(500);
	threadPoolProfile.setAllowCoreThreadTimeOut(false);
	threadPoolProfile.setRejectedPolicy(ThreadPoolRejectedPolicy.Discard);
	return threadPoolProfile;
}
 
开发者ID:LuatixHQ,项目名称:openex-worker,代码行数:11,代码来源:OpenexContext.java

示例10: threadPoolProfileExecutor

import org.apache.camel.ThreadPoolRejectedPolicy; //导入依赖的package包/类
private ThreadPoolProfile threadPoolProfileExecutor() {
	//Define custom thread pool profile
	ThreadPoolProfile threadPoolProfile = new ThreadPoolProfile("openex-worker-thread-profile");
	threadPoolProfile.setPoolSize(20);
	threadPoolProfile.setMaxPoolSize(40);
	threadPoolProfile.setMaxQueueSize(1000);
	threadPoolProfile.setAllowCoreThreadTimeOut(false);
	threadPoolProfile.setRejectedPolicy(ThreadPoolRejectedPolicy.CallerRuns);
	return threadPoolProfile;
}
 
开发者ID:LuatixHQ,项目名称:openex-worker,代码行数:11,代码来源:OpenexContext.java

示例11: resolveRejectedPolicy

import org.apache.camel.ThreadPoolRejectedPolicy; //导入依赖的package包/类
protected ThreadPoolRejectedPolicy resolveRejectedPolicy(RouteContext routeContext) {
    if (getExecutorServiceRef() != null && getRejectedPolicy() == null) {
        ThreadPoolProfile threadPoolProfile = routeContext.getCamelContext().getExecutorServiceManager().getThreadPoolProfile(getExecutorServiceRef());
        if (threadPoolProfile != null) {
            return threadPoolProfile.getRejectedPolicy();
        }
    }
    return getRejectedPolicy();
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:10,代码来源:ThreadsDefinition.java

示例12: ThreadsProcessor

import org.apache.camel.ThreadPoolRejectedPolicy; //导入依赖的package包/类
public ThreadsProcessor(CamelContext camelContext, ExecutorService executorService, boolean shutdownExecutorService, ThreadPoolRejectedPolicy rejectedPolicy) {
    ObjectHelper.notNull(camelContext, "camelContext");
    ObjectHelper.notNull(executorService, "executorService");
    ObjectHelper.notNull(rejectedPolicy, "rejectedPolicy");
    this.camelContext = camelContext;
    this.executorService = executorService;
    this.shutdownExecutorService = shutdownExecutorService;
    this.rejectedPolicy = rejectedPolicy;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:10,代码来源:ThreadsProcessor.java

示例13: DefaultExecutorServiceManager

import org.apache.camel.ThreadPoolRejectedPolicy; //导入依赖的package包/类
public DefaultExecutorServiceManager(CamelContext camelContext) {
    this.camelContext = camelContext;

    defaultProfile = new ThreadPoolProfile(defaultThreadPoolProfileId);
    defaultProfile.setDefaultProfile(true);
    defaultProfile.setPoolSize(10);
    defaultProfile.setMaxPoolSize(20);
    defaultProfile.setKeepAliveTime(60L);
    defaultProfile.setTimeUnit(TimeUnit.SECONDS);
    defaultProfile.setMaxQueueSize(1000);
    defaultProfile.setAllowCoreThreadTimeOut(false);
    defaultProfile.setRejectedPolicy(ThreadPoolRejectedPolicy.CallerRuns);

    registerThreadPoolProfile(defaultProfile);
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:16,代码来源:DefaultExecutorServiceManager.java

示例14: testThreadsRejectedExecution

import org.apache.camel.ThreadPoolRejectedPolicy; //导入依赖的package包/类
public void testThreadsRejectedExecution() throws Exception {
    context.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("seda:start").errorHandler(deadLetterChannel("mock:failed"))
                    .to("log:before")
                    // will use our custom pool
                    .threads()
                    .maxPoolSize(1).poolSize(1) // 1 thread max
                    .maxQueueSize(1)            // 1 queued task
                    //(Test fails whatever the chosen policy below)
                    .rejectedPolicy(ThreadPoolRejectedPolicy.Abort)
                    .delay(1000)
                    .to("log:after")
                    .to("mock:result");
        }
    });
    context.start();

    getMockEndpoint("mock:result").expectedMessageCount(2);
    getMockEndpoint("mock:failed").expectedMessageCount(1);

    template.sendBody("seda:start", "Hello World"); // will block
    template.sendBody("seda:start", "Hi World");    // will be queued
    template.sendBody("seda:start", "Bye World");   // will be rejected

    assertMockEndpointsSatisfied();
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:29,代码来源:ThreadsRejectedExecutionWithDeadLetterTest.java

示例15: testThreadsRejectedExecutionWithRedelivery

import org.apache.camel.ThreadPoolRejectedPolicy; //导入依赖的package包/类
public void testThreadsRejectedExecutionWithRedelivery() throws Exception {
    context.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("seda:start").errorHandler(deadLetterChannel("mock:failed").maximumRedeliveries(5))
                    .to("log:before")
                    // will use our custom pool
                    .threads()
                    .maxPoolSize(1).poolSize(1) // 1 thread max
                    .maxQueueSize(1)            // 1 queued task
                    //(Test fails whatever the chosen policy below)
                    .rejectedPolicy(ThreadPoolRejectedPolicy.Abort)
                    .delay(1000)
                    .to("log:after")
                    .to("mock:result");
        }
    });
    context.start();

    getMockEndpoint("mock:result").expectedMessageCount(3);
    getMockEndpoint("mock:failed").expectedMessageCount(0);

    template.sendBody("seda:start", "Hello World"); // will block
    template.sendBody("seda:start", "Hi World");    // will be queued
    template.sendBody("seda:start", "Bye World");   // will be rejected and queued on redelivery later

    assertMockEndpointsSatisfied();
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:29,代码来源:ThreadsRejectedExecutionWithDeadLetterTest.java


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