Skip to content

Commit

Permalink
Merge pull request #2 from yangkw/master
Browse files Browse the repository at this point in the history
增加线程池
  • Loading branch information
javagaorui5944 authored Nov 17, 2017
2 parents 1cdd7c3 + 975aa1b commit ff31ecf
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
1 change: 1 addition & 0 deletions ProxyIpPool
Submodule ProxyIpPool added at e3f8bd
8 changes: 5 additions & 3 deletions src/main/java/com/myapp/main/MaintenanceService.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,13 @@ public void execute(JobExecutionContext jobExecutionContext) throws JobExecution
countLock = size;
CountDownLatch countDownLatch = new CountDownLatch(countLock);

ExecutorService executor= Executor.newMyexecutor(size);
for (int j = 0; j < size; j++) {
A a = new A(j, z,countDownLatch);
Thread t1 = new Thread(a);
t1.setName(String.valueOf(j));
t1.start();
// Thread t1 = new Thread(a);
executor.execute(a);
// t1.setName(String.valueOf(j));
// t1.start();
}
try {
countDownLatch.await();
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/com/myapp/util/Executor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.myapp.util;

import java.util.concurrent.*;

/**
* Created by 杨凯文 on 2017/11/17 0017.
*/
public class Executor{
/**
* Cannot instantiate.
*/
public static ExecutorService newMyexecutor(int size) {
return new ThreadPoolExecutor(size,size+10,
1, TimeUnit.MINUTES,new ArrayBlockingQueue<Runnable>(16));
}
}

0 comments on commit ff31ecf

Please sign in to comment.