SimpleThreadPool.java 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /**
  2. *
  3. * Copyright (c) behosoft Co.,Ltd.
  4. * All Rights Reserved.
  5. *
  6. * This software is the confidential and proprietary information of behosoft.
  7. * (Social Security Department). You shall not disclose such
  8. * Confidential Information and shall use it only in accordance with
  9. * the terms of the license agreement you entered into with behosoft.
  10. *
  11. * Distributable under GNU LGPL license by gnu.org
  12. */
  13. package com.behosoft.util;
  14. import java.util.concurrent.BlockingQueue;
  15. import java.util.concurrent.LinkedBlockingQueue;
  16. import java.util.concurrent.ThreadPoolExecutor;
  17. import java.util.concurrent.TimeUnit;
  18. /**
  19. *
  20. * <p>
  21. * Title: 百弘电商物流标准版_[]_[模块名]
  22. * </p>
  23. * <p>
  24. * Description: [描述该类概要功能介绍]
  25. * </p>
  26. * @author jiangyonghua
  27. * @version 1.0 2013-9-23
  28. * @author (lastest modification by )
  29. * @since 1.0
  30. */
  31. public class SimpleThreadPool extends ThreadPoolExecutor {
  32. public SimpleThreadPool() {
  33. this(4, 8, new LinkedBlockingQueue<Runnable>());
  34. }
  35. public SimpleThreadPool(int corePoolSize) {
  36. this(corePoolSize, corePoolSize, new LinkedBlockingQueue<Runnable>());
  37. }
  38. public SimpleThreadPool(int corePoolSize, int maximumPoolSize) {
  39. this(corePoolSize, maximumPoolSize, new LinkedBlockingQueue<Runnable>());
  40. }
  41. public SimpleThreadPool(int corePoolSize, int maximumPoolSize,
  42. BlockingQueue blockingQueue) {
  43. super(corePoolSize, maximumPoolSize, 5, TimeUnit.SECONDS, blockingQueue);
  44. }
  45. @Override
  46. public synchronized void execute(Runnable task) {
  47. // 如果此任务已经在队列中,立即返回
  48. if (this.getQueue().contains(task))
  49. return;
  50. super.execute(task);
  51. }
  52. }