java开源线程池,talent-thread-pool-2.0.0公布:java线程池框架

talent-thread-pool-2.0.0发布:java线程池框架

talent-thread-pool是什么?

talent-thread-pool是基于jdk5内置线程池的封装,省却你一些事件的框架

1、帮你完成使用线程池所带来的繁琐的同步安全工作

2、为你提供一个更靠谱的RejectedExecutionHandler(jdk自带的是抛异常,本框架默认的是用定时继续提交)

3、为你提供一个更友好的ThreadFactory(jdk自带的Factory产生出来的Thread名字是形如thread-pool-1的,本框架默认的是形如:myname-1,其中“myname”是应用提供的参数)

4、提供更简单的ThreadPoolExecutor构造器,当然你也可以根据业务需要构造更细化的ThreadPoolExecutor对象。

快速使用

1、构造SynRunnableThreadPoolExecutor

SynRunnableThreadPoolExecutor threadExecutor = new SynRunnableThreadPoolExecutor("quickstart-thread-pool");

2、实现你的业务Runnable(理论上只需要实现AbstractSynRunnable即可,但一般都是带上队列的,所以本框架也提供了队列AbstractQueueRunnable)

public class QuickStartRunnable extends AbstractQueueRunnable

{

private static java.util.concurrent.atomic.AtomicLong atomicLong = new AtomicLong();

@Override

public void run()

{

checkSyn();

T t = null;

while ((t = this.getMsgQueue().poll()) != null)

{

System.out.println(t.toString() + "--" + atomicLong.incrementAndGet());

}

}

/**

* 检查线程池是不是同步调用runnable的(在同一时刻,只有同一个runnable对象被调用)。

*/

private static void checkSyn()

{

String threadName = Thread.currentThread().getName();

File dir = new File("d:/log/dfd/");

dir.mkdirs();

File f = new File(dir, threadName + ".txt");

if (!f.exists())

{

try

{

f.createNewFile();

} catch (IOException e)

{

e.printStackTrace();

}

}

}

}

3、提交业务Runnable到SynRunnableThreadPoolExecutor

threadExecutor.execute(quickStartRunnable);

具体可以参看com.talent.platform.threadpool.quickstart.QuickStartMain和com.talent.platform.threadpool.quickstart.QuickStartRunnable

谁在使用

1、某通讯设备商的网管系统,

2、本人自己在项目中使用,下面的这个图可以让大家放心使用(本框架+talent-socket框架实现的最小smpp协议)。这个图展示了每秒收发3.2W条数据的场景(3.2w=8K*4)

050718669.jpg

图1:收发速度3.2w/s

050718670.jpg

图2:稳定性:用5K的速度跑了3000多万数据,没有任何丢包

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值