Commit 65d30f1a authored by 刘文胜's avatar 刘文胜

1111

parent fc3f6d25
...@@ -29,7 +29,9 @@ import com.hdp.pi.wechat.messages.NewUserMessage; ...@@ -29,7 +29,9 @@ import com.hdp.pi.wechat.messages.NewUserMessage;
public final class IMManager { public final class IMManager {
private static Log log=LogFactory.getLog(IMManager.class); private static Log log=LogFactory.getLog(IMManager.class);
private static ExecutorService pool = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors() * 2); private static int poolSize = Runtime.getRuntime().availableProcessors() * 2;
private static ExecutorService pool = Executors.newFixedThreadPool(poolSize);
private static CopyOnWriteArrayList<Waiter> waiters = new CopyOnWriteArrayList<Waiter>(); private static CopyOnWriteArrayList<Waiter> waiters = new CopyOnWriteArrayList<Waiter>();
...@@ -87,17 +89,13 @@ public final class IMManager { ...@@ -87,17 +89,13 @@ public final class IMManager {
waiters.remove(w); waiters.remove(w);
} }
static{ static{
int pross = Runtime.getRuntime().availableProcessors(); for(int i=0;i<poolSize;i++){
if(pross == 0 ){
pross = 1;
}
for(int i=0;i<pross;i++){
pool.execute(new Runnable() {//消息发射器 pool.execute(new Runnable() {//消息发射器
public void hand(){ public void hand(){
AbstractMessage e=queue.poll(); AbstractMessage e=queue.poll();
if(e == null){ if(e == null){
try { try {
Thread.sleep(50); Thread.sleep(10);
} catch (InterruptedException e1) { } catch (InterruptedException e1) {
} }
return ; return ;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment