本文介绍了ScheduledthreadPool()函数可以多次使用?它会对线程的处理产生影响吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 scheduledThreadPool = Executors.newScheduledThreadPool(Runtime.getRuntime()。availableProcessors()); 

scheduledThreadPool1 = Executors.newScheduledThreadPool(Runtime.getRuntime()。availableProcessors());

while (mNumberOfChatToGenerate!= 0){
WebChatTask chatWork = new WebChatTask(mConfig,chatId ++);
System.out.println( 当前延迟: + mCurrDelay);
scheduledThreadPool.schedule(chatWork,mCurrDelay * chatId,TimeUnit.SECONDS);

mNumberOfChatToGenerate--;

WebChatTask chatWork1 = new WebChatTask(mConfig,chatId ++);
scheduledThreadPool1.schedule(chatWork1,mCurrDelay * chatId,TimeUnit.SECONDS);
mNumberOfChatToGenerate--;
}
解决方案

scheduledThreadPool = Executors.newScheduledThreadPool(Runtime.getRuntime().availableProcessors());

scheduledThreadPool1 = Executors.newScheduledThreadPool(Runtime.getRuntime().availableProcessors());

while(mNumberOfChatToGenerate!=0){
  WebChatTask chatWork = new WebChatTask(mConfig,chatId++);
  System.out.println("Current delay : " + mCurrDelay);
            scheduledThreadPool.schedule(chatWork, mCurrDelay * chatId, TimeUnit.SECONDS);

  mNumberOfChatToGenerate--;

  WebChatTask chatWork1 = new WebChatTask(mConfig,chatId++);
  scheduledThreadPool1.schedule(chatWork1, mCurrDelay * chatId, TimeUnit.SECONDS);
  mNumberOfChatToGenerate--;
}
解决方案


这篇关于ScheduledthreadPool()函数可以多次使用?它会对线程的处理产生影响吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 19:15