# concurrent-limiter **Repository Path**: bilbodai/concurrent-limiter ## Basic Information - **Project Name**: concurrent-limiter - **Description**: java并发限流框架 - **Primary Language**: Java - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 16 - **Forks**: 0 - **Created**: 2015-10-13 - **Last Updated**: 2021-02-17 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README ## Concurrent Limiter It's very simple to use. #### How to use first declare your service : ```java @RateLimit public class HelloService { @QPSRate(rate = 1) public void sayPerSecond() { System.out.println("say one per second"); } @QPSRate(rate = 0.5) public void sayPer2Second() { System.out.println("say one per 2 seconds"); } public void sayData(@DPSRate(rate = 1) byte[] data) { System.out.println("say data "); } } ``` 1. write a service class and declare with `@RateLimit ` annotation. 2. put `@QPSRate`annotation upon the method you want to limit, for sake of limitation you need give the `rate` value. `rate` value control the total number of execution within a second. 3. put `@DPSRate` annotation besides one of method paramethers, you don't have to give the `rate`. it will automatically evaluate by: 1. if parameter is a number, rate would be that value 2. if parameter is an array, rate would be size of it ### Use without setting up spring framework ```java RateLimitContext context = new RateLimitContext(); RateLimitRuntime rateLimitRuntime = new RateLimitRuntime(context); context.addRateLimiters(HelloService.class); final HelloService service = rateLimitRuntime.create(HelloService.class); for (int i = 0; i < 5; i++) { executorService.submit(new Runnable() { @Override public void run() { service.sayPerSecond(); } }); } executorService.shutdown(); ``` ### Use with spring framework ```xml ``` - be care of `xmlns:rate="http://www.edream.cf/schema/ratelimit` give the schemaLocation to `http://www.edream.cf/schema/ratelimit.xsd` and give `annotation-driven` scan packages. all work will be done. ```java @Resource private HelloService service; ``` use spring `DI` to reference your service. and enjoy it! ### How to get it - **maven** ``` net.oschina.bilbodai.concurrent concurrent-limiter 1.0.0-SNAPSHOT ```