forked from wycm/zhihu-crawler
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
y.wang
committed
Jan 21, 2017
1 parent
80f436f
commit 884a7db
Showing
13 changed files
with
115 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
src/main/java/com/crawl/core/util/SimpleThreadPoolExecutor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package com.crawl.core.util; | ||
|
||
|
||
import java.util.concurrent.*; | ||
|
||
public class SimpleThreadPoolExecutor extends ThreadPoolExecutor{ | ||
private String threadPoolName; | ||
public SimpleThreadPoolExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime, | ||
TimeUnit unit, BlockingQueue<Runnable> workQueue, String threadPoolName) { | ||
super(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue); | ||
this.threadPoolName = threadPoolName; | ||
} | ||
|
||
public SimpleThreadPoolExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime, | ||
TimeUnit unit, BlockingQueue<Runnable> workQueue, ThreadFactory threadFactory, | ||
String threadPoolName) { | ||
super(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue, threadFactory); | ||
this.threadPoolName = threadPoolName; | ||
} | ||
|
||
public SimpleThreadPoolExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, | ||
BlockingQueue<Runnable> workQueue, RejectedExecutionHandler handler, | ||
String threadPoolName) { | ||
super(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue, handler); | ||
this.threadPoolName = threadPoolName; | ||
} | ||
|
||
public SimpleThreadPoolExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, | ||
BlockingQueue<Runnable> workQueue, ThreadFactory threadFactory, | ||
RejectedExecutionHandler handler, String threadPoolName) { | ||
super(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue, threadFactory, handler); | ||
this.threadPoolName = threadPoolName; | ||
} | ||
|
||
/** | ||
* 修改thread name | ||
* @param t | ||
* @param r | ||
*/ | ||
@Override | ||
protected void beforeExecute(Thread t, Runnable r) { | ||
if (t.getName().startsWith("pool-")){ | ||
t.setName(t.getName().replaceAll("pool-\\d", this.threadPoolName)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters